Last post Mar 18, 2008 04:49 PM by PinalBhatt
Jul 15, 2007 11:48 AM|Ad_|LINK
It is possible to grab the HTML output from a custom control by doing the following:
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htmlTw = new HtmlTextWriter(sw);
string controlsHTML = sb.ToString();
I was wondering how you could do the same of a User control and its entire contents. Take an example that a user control contains some standard HTML markup as well as a GridView control and a Button control. The GridView would normally be data bound in the
If you use LoadControl("target.ascx") and grab the rendered contents:
A > Only the standard HTML markup is retrieved
B > The GridView does not get data bound
How can you bind the grid view, and then retrieve the entire contents of the user control?
Jul 15, 2007 12:33 PM|Ad_|LINK
I answered my own question. the solution is actually pretty obvious. You have to simply override the Rendercontrol method within the user control:
public override void RenderControl(HtmlTextWriter writer)
GridView.DataSource = myDataSource;
Mar 18, 2008 04:49 PM|PinalBhatt|LINK
When I try with following code in load event of page
I get error : Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
where GridView1 is a gridview control placed in dg.ascx.