检索特定元素的HTML中ASCX

问题描述:

Possible Duplicate:
Retrieve contents of HtmlGenericControl inside ASCX WebControl检索特定元素的HTML中ASCX

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

我在拉数据服务器端时遇到问题。我试图用传统的方法(代码里面的ASCX的后面),例如:

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

但我发现了一个错误:

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

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

(这是一个问题,因为Button_Click发生在ASCX用户控件的代码中,而不是ASPX页面,在该页面有这不是一个选项。)

+0

得到这个结果,这是关系到ASP.NET开发?和/或C#? 'html'和'render'标签看起来没有帮助/正确。考虑改变这些其他标签是否准确。 – 2012-07-23 23:42:29

+0

完成。接得好。 – Wesley 2012-07-23 23:50:30

+0

如果我的理解是正确的,当按下按钮时,您需要找回先前绑定到中继器的数据以通过电子邮件发送它? – Jupaol 2012-07-24 00:03:48

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

enter image description here

我发布的代码在你的simplified question