在 asp.net (C#) (.cs) 页面中编写 html 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1078933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Write html code inside asp.net (C#) (.cs) page
提问by Ahmad Farid
I would like to add some paragraphs or new lines or words dynamically but I want to make gaps between every part and the other. How is it possible to do that in the c# code page?
我想动态添加一些段落或新行或单词,但我想在每个部分和其他部分之间留出空隙。如何在 c# 代码页中做到这一点?
回答by Canavar
You can use LiteralControl to add HTML tags like that :
您可以使用 LiteralControl 添加这样的 HTML 标签:
Page.Controls.Add(new LiteralControl("<p>New<br />Line</p>"));
回答by Useful_Info
I was able to do it using lblMessage.Text
and then replacing the "
character by the '
character in the HTML code...
我可以使用HTML 代码中的字符lblMessage.Text
替换该"
字符'
...
lblMessage.Text = "<a href='javascript:history.go(-1)'>Go Back</a>";
回答by Daan
Ideally, you don't want to add markup code to your codebehind pages. But if you must, you can perhaps use HTML's <p>
element to make different paragraphs. By default, each paragraph has some top and bottom margin to separate it from other elements on the page.
理想情况下,您不希望向代码隐藏页面添加标记代码。但如果必须的话,您或许可以使用 HTML 的<p>
元素来制作不同的段落。默认情况下,每个段落都有一些顶部和底部边距,以将其与页面上的其他元素分开。
回答by this. __curious_geek
You can do this using HttpModule. HttpModule can intercept request and response and modify as you need.
您可以使用HttpModule执行此操作。HttpModule 可以拦截请求和响应,并根据需要进行修改。
回答by misnyo
Maybe this is the proper way: http://msdn.microsoft.com/en-us/library/620b4fzf(VS.71).aspx
也许这是正确的方法:http: //msdn.microsoft.com/en-us/library/620b4fzf(VS.71).aspx
So if you like to add what a paragraph with a break inside:
因此,如果您想添加一个内部有中断的段落:
HtmlGenericControl paragraph = new HtmlGenericControl("p");
paragraph.Controls.Add(new HtmlGenericControl("br"));
Page.Controls.Add(paragraph );