渲染控制错误[未处理异常] [英] Render control error[un handle exception]

查看:96
本文介绍了渲染控制错误[未处理异常]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

使用渲染控件Unhandle异常时出现错误,显示仅在表格标签中放置了GridView.

Hi All,

I am getting error while using render control Unhandle exception it showing i place gridview in form tag only.

XmlTextReader xtr = new XmlTextReader("http://localhost:50197/Trail4/xml/xmltest.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(xtr);
        xtr.Close();
        GridView1.DataSource = ds;
           
        
        GridView1.DataBind();
        Response.ClearContent();
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "xml.doc"));
        Response.Charset = "";
        Response.ContentType = "application/ms-word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
       GridView1.RenderControl(htw);
      
        Response.Write(sw.ToString());
        Response.End();

推荐答案

类型为"GridView"的控件"GridView1"必须放置在表单标签内使用runat = server
当尝试将GridView控件导出为Word,Excel,PDF,CSV或任何其他格式时,会发生上述异常.

原因:
.NET编译器认为该控件未添加到表单中并被呈现.

解决方案:
告诉编译器该控件由overridingVerifyRenderingInServerForm事件显式呈现.
像这样的东西:
Control ''GridView1'' of type ''GridView'' must be placed inside a form tag with runat=server
The above exception occurs when one tries to export a GridView control to Word, Excel, PDF, CSV or any other formats.

Reason:
.NET compiler thinks that the control is not added to the form and is rendered.

Solution:
Tell compiler that the control is rendered explicitly by overriding the VerifyRenderingInServerForm event.
Something like:
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}


此错误/问题已报告& MS在此处建议的分辨率: RenderControl不适用于GridView [^ ]


This Error/issue reported & resolution suggested by MS here: RenderControl doesn''t work for GridView[^]


这篇关于渲染控制错误[未处理异常]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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