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

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

问题描述

我有一个或 ContentPlaceHolder NOT 被放置在一个RunAt服务器窗体中。



我有这两个,所以不是这样的。



我的 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 LinkBut​​ton 控件,但每个都包含 runat =server子句。





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



如果不,我的导出方法有什么可以配置,以便DataGrid数据全部解释为文本?



我可以创建一个空白的DataGrid,然后走过填写DataGrid,仅写入每个字段的文本 - 但是如果绝对需要,我只想这样做。

解决方案

我相信你只需要ov反映检查表单的方法。您不需要为该方法添加任何逻辑。只需将以下代码添加到您的代码中:

  public override void VerifyRenderingInServerForm(Control control){} 

ETA:您可能还需要设置 EnableEventValidation =false <%@ Page /> 元素


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天全站免登陆