Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating html from code behind

In my .aspx.cs I have a code that reads a .xml file and I deserialize the xml into 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?

like image 209
aherlambang Avatar asked Jul 08 '26 11:07

aherlambang


2 Answers

The div you mentioned from the aspx markup:

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

Your code behind:

PostContent.Text = Post.GeneratedHtml;
like image 135
Joel Coehoorn Avatar answered Jul 10 '26 03:07

Joel Coehoorn


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;
like image 24
Ray Avatar answered Jul 10 '26 02:07

Ray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!