问题
Possible Duplicate:
Retrieve contents of HtmlGenericControl inside ASCX WebControl
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.
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();
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?
(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.)
回答1:
If my understanding is correct this is the output you are looking for:
I posted the code to get this result in your simplified question
来源:https://stackoverflow.com/questions/11622094/retrieve-html-of-specific-element-in-ascx