G
Guest
I have a GridView control in page called which is inheriting
from a MasterPage. The normal code to export to GridView does not work and
gives me an error - "Control of type GridView must be placed inside form tag
with runat = server". I understand that this is because my Masterpage has the
formtag and not the eventslisting page, but cannot figure a workaround.
I have tried overriding VerifyRenderingInServerForm and everything else I
can think of with the same results.
Code in Content Page:
this.VerifyRenderingInServerForm(this.GridView1);
((MasterPage)this.Master).ExportToExcel("GridView1");
Code in MasterPage:
public void ExportToExcel(string oGridViewName)
{
Response.ContentType = "application/xls";
Response.AddHeader("content-disposition", "inline;
filename=c:\\Report.XLS");
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
GridView oGrid =
(GridView)this.FindControl("ContentPlaceholder1").FindControl("UpdatePanel1").FindControl(oGridViewName);
oGrid.AllowSorting = false;
oGrid.RenderControl(htmlWriter);
Response.Write(sw);
Response.End();
}
from a MasterPage. The normal code to export to GridView does not work and
gives me an error - "Control of type GridView must be placed inside form tag
with runat = server". I understand that this is because my Masterpage has the
formtag and not the eventslisting page, but cannot figure a workaround.
I have tried overriding VerifyRenderingInServerForm and everything else I
can think of with the same results.
Code in Content Page:
this.VerifyRenderingInServerForm(this.GridView1);
((MasterPage)this.Master).ExportToExcel("GridView1");
Code in MasterPage:
public void ExportToExcel(string oGridViewName)
{
Response.ContentType = "application/xls";
Response.AddHeader("content-disposition", "inline;
filename=c:\\Report.XLS");
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
GridView oGrid =
(GridView)this.FindControl("ContentPlaceholder1").FindControl("UpdatePanel1").FindControl(oGridViewName);
oGrid.AllowSorting = false;
oGrid.RenderControl(htmlWriter);
Response.Write(sw);
Response.End();
}