Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 30, 2010 07:55 AM by The Schickster
Aug 12, 2006 02:13 AM|LINK
I want to get the GridView's html code before page render. I just used GridView.RenderControl() method. However I got a message that said GridView Type Control must be put in Form tag with runat=server. What should I do?
----------Here Comes My Code---------------
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView gv = new GridView();
gv.DataSourceID = "SqlDataSource1";
catch (Exception ex)
this.Label1.Text = stringWrite.ToString();
Aug 14, 2006 05:59 AM|LINK
Sometimes you can get "...must be placed inside a form tag with runat=server" error, when you deal with "asp:panel" or "asp:linkbutton" or whatever else scenarious when htmlform control needs to be rendered for the specified control at run time. The problem
can be solved (thanks, Alex) ovverriding
Page.VerifyRenderingInServerForm Method. Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
So, the code would look like the following (rendering asp:panel containing controls itself):
private void Page_Load(object sender, EventArgs e)
System.IO.StringWriter stringWriter =
System.Web.UI.HtmlTextWriter htmlWriter =
string s = stringWriter.ToString();
public override void
Aug 14, 2006 02:52 PM|LINK
it does work, thank you
Feb 23, 2007 02:18 PM|LINK
Thank you guys. Your line of code really save me time for research.
I'm trying to do the exact same thing, and it works now with your override void VerifyRenderingInServerForm(Control control)
Jul 21, 2008 10:33 AM|LINK
Very Thank you guys. Your line of code really save me time for research. I'm trying to do the exact same thing, and it works now with your override void VerifyRenderingInServerForm(Control control) code.
Apr 13, 2009 04:44 AM|LINK
Everything that I've tried doesn't work, despite it seems to be successful for everyone else! There are lots of links that describe using the VerifyRenderingInServerForm, but it's not working for me. I'm currently in a VB.NET project that's using framework
3.5 and I've added this, which I believe, is similar to the code that you recommended that I add....
Sub VerifyRenderingInServerForm(ByVal control
' Verifies that the control is rendered
What am I missing? Thoughts?
Apr 15, 2009 08:02 PM|LINK
Apr 16, 2009 05:04 PM|LINK
What if I'm using all this code in a usercontrol? There isn't this method in the base class...... Now what?
Jul 01, 2009 07:15 AM|LINK
Really Thanks. The working VB code
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)
Dec 24, 2009 07:25 AM|LINK
What if I'm building the controls dynamicly (they are not as a part of the page when the VerifyRenderingInServerForm do fire)?!
...... Building the panel dynamicly from xsd template
Do While xpni.MoveNext()
Dim filename As String = xpni.Current.GetAttribute("id", String.Empty) & ".ascx"
Dim ieb As InputElementBase = CType(LoadControl(Pages.Dirs.Controls.InputElements & filename), InputElementBase)
p.Controls.Add(New LiteralControl("<table><tr style=""height:2px;""><td></td></tr></table>"))
Session("InputForm" & form.ID) = p
....... Then in other page
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
Public Shadows Function RenderControl(ByVal ctrl As Control) As String
Dim sb As StringBuilder = New StringBuilder
Dim tw As StringWriter = New StringWriter(sb)
Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
sBody = Tools.MakeHtmlBody(CType(Session("toolstoexcels"), DataTable), _
CType(Session("second").id, Integer), _
RenderControl(CType(Session("InputForm1"), Panel)), _
RenderControl(CType(Session("InputForm2"), Panel)), _
RenderControl(CType(Session("InputForm3"), Panel)), _
// Here I'm falling when performing RenderControl
...... and finaly it supose to do
Public Shared Function MakeHtmlBody(ByVal dt As DataTable, _
ByVal ToolList As String, _
ByVal SecondaryID As Integer, _
ByVal InputForm1 As String, _
ByVal InputForm2 As String, _
ByVal InputForm3 As String, _
ByVal InputForm4 As String) As String
s += InputForm1 + _
InputForm2 + _
InputForm3 + _
InputForm4 + _