RenderControl on MasterPage - "must be placed inside form tag" err

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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top