Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - get HTML of control in ASP.NET 2.0

 
Thread Tools Search this Thread
Old 10-27-2005, 04:26 PM   #1
Default get HTML of control in ASP.NET 2.0


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=?=
  Reply With Quote
Old 11-15-2005, 06:04 AM   #2
Ryan McHale
 
Posts: n/a
Default Re: get HTML of control in ASP.NET 2.0
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
  Reply With Quote
Old 11-20-2005, 01:36 PM   #3
trendytim@gmail.com
 
Posts: n/a
Default Re: get HTML of control in ASP.NET 2.0
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46