检索ASCX特定元素的HTML [英] Retrieve HTML of specific element in ASCX

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

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/11622541/retrieve-contents-of-htmlgenericcontrol-inside-ascx-webcontrol\">Retrieve内ASCX的WebControl

我有嵌入多个页面的ASCX控件,从数据库拉页上下文数据,它绑定到一个中继器,然后有一个Button_Click事件,将中继器的内容通过电子邮件发送给用户。

I have an ASCX control embedded on multiple pages that pulls page-contextual data from a Database, binds it to a repeater, and then has a Button_Click event that will email the contents of the repeater to a user.

我无法拉低数据服务器端。我试图用传统的方法(里面的code中的ASCX的后面),例如:

I'm having trouble pulling the data server side. I tried using traditional methods (Inside the code behind of the ASCX) such as:

var sw = new System.IO.StringWriter();
var hw = new HtmlTextWriter(sw);
quotecontent.RenderControl(hw);

但我发现了一个错误:

But I'm getting an error:

RegisterForEventValidation can only be called during Render();
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: RegisterForEventValidation can only be called during Render();

这听起来像我可能无法使用ASCX文件里向HtmlTextWriter?这是真的还是我做错了?如果这是真的,我应该如何访问该元素的内容?

It sounds like I may not be able to use an HtmlTextWriter inside of an ASCX file? Is that true or am I doing it wrong? If it is true, how should I access the content of the element?

(这是一个问题,因为Button_Click发生在ASCX用户控件的code里面,而不是aspx页面,在页面说完这是不是一种选择。)

(This is an issue because the Button_Click happens inside the code of the ASCX user control, not the ASPX Page. Having this in the Page is not an option.)

推荐答案

如果我的理解是正确的,这是你正在寻找的输出:

If my understanding is correct this is the output you are looking for:

我张贴的code在得到这个结果的简化问题

I posted the code to get this result in your simplified question

这篇关于检索ASCX特定元素的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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