开发者

generating html from code behind

In my .aspx.cs I have a code that reads a .xml file and I deserialize the xml i开发者_JAVA技巧nto an object called Post. Problem is that in my .aspx page I have a div and I want to fill in the content of this div from code behind using the html generated from the code behind.. How can I do this?


The div you mentioned from the aspx markup:

<div><asp:Literal ID="PostContent" runat="server" /></div>

Your code behind:

PostContent.Text = Post.GeneratedHtml;


Use the InnerHtml or InnerText properties of the div to load your text. The div will be a control of type HtmlGenericControl.

In your page:

<div id="content" runat="server" />

In your codebehind:

protected HtmlGenericControl content;

content.InnerHtml = myGeneratedText;


Use a Literal control. Example here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜