G
Guest
Hi All.
All I want to do is get the HTML of a control on my page at postback into a
string in my code behind.
In ASP.NET 1.0 this used to be simple:
Dim lStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim lHtmlTextWriter As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(lStringWriter)
SomeServerControl.RenderControl(lHtmlTextWriter)
Dim lStrControlHTML As String = lStringWriter.ToString()
This however would generate an error in ASP.NET 1.0 because the control
would be treated as if not inside a form tag.
To go around this problem all I had to do is overwrite this check like so:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
End Sub
But now in ASP.NET 2.0 this does not work anymore. I get this error message:
RegisterForEventValidation can only be called during Render();
on this line:
SomeServerControl.RenderControl(lHtmlTextWriter)
this is the trace stack:
[InvalidOperationException: RegisterForEventValidation can only be called
during Render();]
System.Web.UI.ClientScriptManager.RegisterForEventValidation(String
uniqueId, String argument) +239
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
writer) +2370
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer) +36
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +32
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +74
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
All I want to do is get the HTML of a control before it is send to the client.
How do I do this in ASP.NET 2.0?
All I want to do is get the HTML of a control on my page at postback into a
string in my code behind.
In ASP.NET 1.0 this used to be simple:
Dim lStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim lHtmlTextWriter As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(lStringWriter)
SomeServerControl.RenderControl(lHtmlTextWriter)
Dim lStrControlHTML As String = lStringWriter.ToString()
This however would generate an error in ASP.NET 1.0 because the control
would be treated as if not inside a form tag.
To go around this problem all I had to do is overwrite this check like so:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
End Sub
But now in ASP.NET 2.0 this does not work anymore. I get this error message:
RegisterForEventValidation can only be called during Render();
on this line:
SomeServerControl.RenderControl(lHtmlTextWriter)
this is the trace stack:
[InvalidOperationException: RegisterForEventValidation can only be called
during Render();]
System.Web.UI.ClientScriptManager.RegisterForEventValidation(String
uniqueId, String argument) +239
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
writer) +2370
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer) +36
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +32
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +74
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
All I want to do is get the HTML of a control before it is send to the client.
How do I do this in ASP.NET 2.0?