'LinkBut​​ton' 类型的控件 xxx 必须放置在带有 runat=server 的表单标签内 [英] Control xxx of type 'LinkButton' must be placed inside a form tag with runat=server

查看:18
本文介绍了'LinkBut​​ton' 类型的控件 xxx 必须放置在带有 runat=server 的表单标签内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 或 ContentPlaceHolder NOT放置在 RunAt Server 表单中.

这两个我都有,所以这里不是这样.

我的 ExportExcelFile 方法捕获了 HttpExceptionRenderControl()(如图所示)上面的截图).该代码如下:

protected void ExportExcelFile(object Sender, EventArgs e) {//导出到excelvar grdResults = (periodCriteria.SelectedValue == "year") ?RollupDG : QuarterDG;var response = HttpContext.Current.Response;响应.清除();response.Charset = String.Empty;response.ContentType = "application/vnd.ms-excel";response.AddHeader("Content-Disposition", "attachment; filename=GlBudgetReport.xls");使用 (var sw = new StringWriter()) {使用 (var htw = new HtmlTextWriter(sw)) {grdResults.RenderControl(htw);response.Write(sw.ToString());response.End();}}}

如下面我的查找结果框中所示,有几个 ASP.NET LinkBut​​ton 控件,但每个控件都包含 runat="server" 子句.

DataGrid 中的 LinkBut​​ton 数据似乎难以呈现为纯文本.

如果没有,我的导出方法中是否有可以配置的内容,以便将 DataGrid 数据全部解释为文本?

我可以创建一个空白的 DataGrid,然后遍历填充的 DataGrid,只写入每个字段的文本 - 但我只想在绝对必要时这样做.

解决方案

我相信您只需要覆盖检查表单的方法.您不需要向该方法添加任何逻辑.只需在后面的代码中添加以下内容:

public override void VerifyRenderingInServerForm(Control control) { }

预计到达时间:您可能还需要在 <%@Page/> 元素中设置 EnableEventValidation="false".

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

The exact error is:

Control 'ctl00_body_RollupDG_ctl02_btnShowGLdetail' of type 'LinkButton' must be placed inside a form tag with runat=server.

I found similar questions on here, but all seem to indicate that this comes from the ASP.NET control NOT being placed within a ContentPlaceHolder or a ContentPlaceHolder NOT being placed within a RunAt Server form.

I have both of these, so that is not the case here.

My ExportExcelFile method catches the HttpException at RenderControl() (as shown in the screenshot above). That code is as follows:

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

As shown in my Find Results box below, there are several ASP.NET LinkButton controls, but each of them does contain the runat="server" clause.

It appears the LinkButton data in the DataGrid has difficulty rendering as Plain Text.

If not, is there something in my export method that can be configured so that the DataGrid data is all interpreted as text?

I could create a blank DataGrid, then walk through the filled DataGrid, writing in only the text of each field - but I only want to do this if it is absolutely necessary.

解决方案

I believe you just need to override the method that checks for a form. You don't need to add any logic to the method. Just add the following to your code behind:

public override void VerifyRenderingInServerForm(Control control) { } 

ETA: You may also need to set EnableEventValidation="false" in the <%@Page /> element.

这篇关于'LinkBut​​ton' 类型的控件 xxx 必须放置在带有 runat=server 的表单标签内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆