可能重复:
Retrieve contents of HtmlGenericControl inside ASCX WebControl
我在多个页面上嵌入了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();
听起来我可能无法在ASCX文件中使用HtmlTextWriter?是真的还是我做错了?如果是,我应该如何访问元素的内容?
(这是一个问题,因为Button_Click发生在ASCX用户控件的代码内,而不是ASPX页面。在页面中有这个不是一个选项。)