怎样才能用C#服务器端元素的innerHTML(与其他服务器端控件内) [英] how can get innerhtml of a server side element with c# (with another server-side controls inside)

查看:180
本文介绍了怎样才能用C#服务器端元素的innerHTML(与其他服务器端控件内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何才能使用C#服务器端元素的innerHTML(带内的另一个服务器端控件)?结果
或什么是与Visual Studio 2010的设计邮件正文的最好方法?结果
I在C#中的一些代码发送电子邮件...(支持HTML体)结果
,所以我寻找一个硬编码的HTML体的景观办法!结果
等制成服务器端DIV设计模式:

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>



但我不能让这innterHtml DIV通过下面的代码我的电子邮件正文:

but i can n't get innterHtml of this div for my email body by below code :

 string s = MainDiv.InnerHtml.ToString();  

错误:

因为内容不是
字面无法获得MainDiv内的内容。

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

我也有内部MainDiv一个服务器端的表,我想动态添加一些数据到这个表。结果
相这种情况我能获取的HTML电子邮件的身体呢?结果
在此先感谢

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

推荐答案

你不能在一个div调用innerHTML的,除非它的内容是文字(即有没有包含在里面的服务器控件)。但是你可以做这样的事情迫使它呈现为一个字符串:

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();

这篇关于怎样才能用C#服务器端元素的innerHTML(与其他服务器端控件内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆