检索ASCX的WebControl里面HtmlGenericControl内容 [英] Retrieve contents of HtmlGenericControl inside ASCX WebControl

查看:122
本文介绍了检索ASCX的WebControl里面HtmlGenericControl内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HtmlGenericControl 这是一个简单的DIV与 RUNAT =服务器

I have an HtmlGenericControl which is a simple DIV with runat=server

此控件嵌入驻留在多个页面的ASCX的WebControl里面。在Page_Load中该元素是由一个中继器是数据绑定到页面的特定数据库中的数据进行填充。

This Control is embedded inside of an ASCX WebControl which resides on multiple pages. At Page_Load this element is populated by a repeater that is data-bound to database data that is Page Specific.

我遇到的问题是似乎ASCX器WebControls不会很轻松地阅读自己的元素的内容。

The trouble I'm having is ASCX WebControls don't seem to read the contents of their own elements very easily.

到目前为止,已经失败:
<一href=\"http://stackoverflow.com/questions/288409/how-do-i-get-the-html-output-of-a-usercontrol-in-net-c\">How我会得到一个用户控件的HTML输出在.NET(C#)?

So far this has failed: How do I get the HTML output of a UserControl in .NET (C#)?

我正在寻找一种方式来获得一个按钮,点击里面的HtmlGenericControl的内容。我会怎么做呢?

I'm looking for a way to get the contents of the HtmlGenericControl inside of a button click. How would I do that?

简化previous问题。的<一个href=\"http://stackoverflow.com/questions/11622094/retrieve-html-of-specific-element-in-ascx#comment15391079_11622094\">Retrieve在ASCX 特定元素的HTML

Simplifying previous question. Retrieve HTML of specific element in ASCX

推荐答案

好吧,我得到它的工作(我认为...)

OK, I got it working (I think...)

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }

ASPX标记

%@ Page EnableEventValidation="false" .....

用户控制$ C $后面

ç

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            var d = new QuestionsContext().GetQuestions();

            this.repeater.DataSource = d;
            this.repeater.DataBind();
        }
    }

    protected void getContent_Click(object sender, EventArgs e)
    {
        var sb = new StringBuilder();

        this.generic.RenderControl(new HtmlTextWriter(new StringWriter(sb)));

        string s = sb.ToString();

        this.Trace.Warn(Server.HtmlEncode(s));
        this.message.Text = Server.HtmlEncode(s);
    }

用户控件标记

<div runat="server" id="generic">
    <asp:Repeater runat="server" ID="repeater" >
        <ItemTemplate>
            <%# Eval("QuestionText") %>
        </ItemTemplate>
    </asp:Repeater>
</div>

<br />
<asp:Button Text="Get content" ID="getContent" runat="server" OnClick="getContent_Click" />
<br />
<asp:Label ID="message" runat="server" />

这篇关于检索ASCX的WebControl里面HtmlGenericControl内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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