An xxx control of type "LinkButton" must be placed inside the form tag using runat = server

I have a DataGrid that I am trying to export when an ASP.NET Button .

error screen

Exact error:

The control 'ctl00_body_RollupDG_ctl02_btnShowGLdetail' of type 'LinkButton' must be placed inside the form tag using runat = server.

I found similar questions here, but everyone seems to indicate that this comes from an ASP.NET control NOT placed in a ContentPlaceHolder or ContentPlaceHolder NOT placed in a RunAt server form.

I have both of them, so it’s not.

ExportExcelFile HttpException RenderControl() ( ). :

protected void ExportExcelFile(object Sender, EventArgs e) { //export to excel
    var grdResults = (periodCriteria.SelectedValue == "year") ? RollupDG : QuarterDG;
    var response = HttpContext.Current.Response;
    response.Clear();
    response.Charset = String.Empty;
    response.ContentType = "application/vnd.ms-excel";
    response.AddHeader("Content-Disposition", "attachment; filename=GlBudgetReport.xls");
    using (var sw = new StringWriter()) {
        using (var htw = new HtmlTextWriter(sw)) {
            grdResults.RenderControl(htw);
            response.Write(sw.ToString());
            response.End();
        }
    }
}

, ASP.NET LinkButton, runat="server".

Find Results

, LinkButton DataGrid .

, - , , DataGrid ?

DataGrid, DataGrid, , , .

+4
1

, , . . :

public override void VerifyRenderingInServerForm(Control control) { } 

ETA: EnableEventValidation="false" <%@Page />.

+6

All Articles