Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can get innerhtml of a server side element with c# (with another server-side controls inside)

how can get innerhtml of a server side element with c# (with another server-side controls inside)?
or what is the best way for designing email body with visual studio 2010?
i have some codes in c# for sending emails ...(supporting html body)
so i am looking for a way for scape of hardcoding html body!
and so 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 can n't get innterHtml of this div for my email body by below code :

 string s = MainDiv.InnerHtml.ToString();  

ERROR :

Cannot get inner content of MainDiv because the contents are not literal.

also i 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 for getting html for email body ?
thanks in advance

like image 841
SilverLight Avatar asked Jul 22 '11 23:07

SilverLight


People also ask

What is innerHTML property?

The innerHTML property returns: The text content of the element, including all spacing and inner HTML tags. The innerText property returns: Just the text content of the element and all its children, without CSS hidden text spacing and tags, except <script> and <style> elements.

What is innerHTML vs value?

value refers to an attribute of a tag, while innerHTML refers to the contents between a tag's beginning and end.


1 Answers

You can't invoke InnerHtml on a div unless its contents are literal (i.e. there aren't server controls contained inside it). But you can force it to render to a string by doing something like this:

var sb = new StringBuilder();
mainDiv.RenderControl(new HtmlTextWriter(new StringWriter(sb)));

string s = sb.ToString();
like image 118
asdfjklqwer Avatar answered Sep 25 '22 05:09

asdfjklqwer