编辑: 已经写了一个很长的回复这让我感到你可以以一种非常规的方式这样做。该页面的HTML应该在.aspx中,而不是在后面的代码中(.aspx.cs)..它不是不可能放在.cs文件中,但“通常”HTML将在.aspx中。为什么?由于你描述的问题确实存在,所以维护是件痛苦的事!通常我们会将C#代码与HTML分开...
在您的示例中,您没有正确处理引号。 “应该成为\”
考虑
myString+= "<div class=" + "clear" + "></div>";
也许应该
myString+= "<div class=\"clear\"></div>";
你也可以考虑这些选项,这取决于你想达到一个什么样以下应该可以帮助您
1字符串文字
如果你想添加一个字符串“完全”,因为它给出,你可以使用字符串文字。你所做的只是在你声明字符串时贴一个@。 (http://www.dotnetperls.com/string-literal)。
您还需要你”,用 “逃离”
例如:
string longstring = @"<h3>Hello</h3><p>Name<sup>®</sup> some text<div class=""clear""></div>";
string longerstring = @"<p>String literals are stored in the metadata format that underlies
all executable C# programs. The metadata format defined in the Common Language
Specification includes a database of tables with headers and rows in all exe
files. There are several predefined streams in the metadata files, including the
#Strings stream and the #US (user strings) stream. The #US stream is used to store
programmer-defined literals. The metadata tables store offsets into this stream.
The stream itself is simply a concatenated series of characters used in the entire
program's strings. The execution engine stores the offsets and tables in memory
and then simply reads a range in the #US stream when you use the string literal.</p>"
2资源
但如果你只是存储页面的静态部分,即HTML片段,您可以使用.resx资源(http://msdn.microsoft.com/en-us/library/ekyft91f(v=vs.80).aspx)...OR
3服务器端包含
甚至可能是服务器端包含
<html>
<body>
<%
Response.WriteFile ("Yourfile.inc")
%>
</body>
</html>
哪里Yourfile.inc是你的文件系统
http://support.microsoft.com/kb/306575
我以为双击了该文件用于转义引号的引号(“”)是VB.NET语法,而\是用于C#的?或者是C#中特定于字符串文字的双引号? – Tim
是的“”是特定的字符串文字:-) – inspite
谢谢 - 我又学到了另一个“小”的东西:) – Tim