![]() |
|
|
|||||||
![]() |
ASP Net - get HTML of control in ASP.NET 2.0 |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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.RegisterForEvent Validation(String uniqueId, String argument) +239 System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter writer) +2370 System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter writer) +36 System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter 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? =?Utf-8?B?ZGFGb3U=?= |
|
|
|
|
#2 |
|
Posts: n/a
|
Is there any solution/workaround to this? Basically the problem is you
cannot render a user control that contains an asp control in it using the RenderControl method.. If you remove the asp control it works fine. but then what your rendering is kind of useless. Ryan McHale |
|
|
|
#3 |
|
Posts: n/a
|
If you set the hidden (from intellisense, but still accessible) public
property EnableEventValidation on the page object you use to load the control to false that should fix the problem. -Tim trendytim@gmail.com |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| implementation of collapsible panel control in asp.net | bhawneshkumar | Software | 0 | 07-17-2009 06:38 AM |
| help required in file upload control in asp.net | Upmanyu | Software | 0 | 03-27-2008 01:51 PM |
| want to display .chm in browser control of ASP.NET 2.0 | pratibhaskhaire | General Help Related Topics | 0 | 02-14-2008 06:23 AM |
| Nested forms and server-side control in ASP.NET | mredelin | Software | 0 | 12-20-2007 09:12 PM |
| ASP.Net 2.0 - Want details view but need control & placement of textboxes etc. | daveydave999 | Software | 0 | 10-05-2007 04:12 PM |