How can one get innerhtml of a server side element with C # (with other server side elements inside)

how to get innerhtml of a server side element with c # (with other server side elements inside)?
or what is the best way to create an email body with visual studio 2010?
I have some codes in C # for sending emails ... (html body support)
so i'm looking for a way to view html body hard coding!
and therefore made a server-side div in design mode:

<div runat="server" id="MainDiv" style="direction: rtl; font: 12px tahoma,arial,sans-serif; width: 700px; background-color: #f5f5ff; border: 2px solid #003366;"> <div id="Header" style="width: 690px; background-color: #637eb0; height: 40px; margin: 5px auto; position: relative;"> <img src="Images/logo.png" alt="logo" title="soscharge" style="width: 200px; position: absolute; top: 4px; left: 10px;" /> <span style="color: #69fbfd; font: bold 13px tahoma,arial,sans-serif; position: absolute; top: 11px; right: 10px;">hi ...</span> </div> <div id="Content" style="padding: 10px 10px;"> <ul style="margin:0px;padding:0px 10px 10px 10px;"> <li> title1 : --- </li> <li> title 2 : <asp:Label ID="lblOredr_Id" runat="server" Text="---" ForeColor="Red"></asp:Label> </li> </ul> <br /> <p style="text-align: center;color:#fd00dc;"> bla bla</p> </div> </div> 

but I cannot get the innterHtml of this div for my email body using the code below:

  string s = MainDiv.InnerHtml.ToString(); 

MISTAKE:

Cannot retrieve the internal contents of MainDiv because the content is not literal.

I also have a server side table inside MainDiv. And I want to add some data dynamically to this table.
with this situation, what can I do to get html for the email body?
thanks in advance

+7
source share
1 answer

You cannot call InnerHtml in a div if its contents are not literal (i.e. there are no server controls in it). But you can make it visualize the line by doing something like this:

 var sb = new StringBuilder(); mainDiv.RenderControl(new HtmlTextWriter(new StringWriter(sb))); string s = sb.ToString(); 
+18
source

All Articles