Solved

ASP.NET 3.5: Problem exporting grid contents to word from a child page: ErrorCode=-2147467259

Posted on 2013-01-13
2
399 Views
Last Modified: 2013-01-14
I am using ASP.NET 3.5 with C# code.  I have gridview by name “gridinfo” in a child page populated by records from a database.  I am using a standard function to export the grid contents to word.
private void exportgridinfotoword()

    {
       
        Response.Clear();
  Response.AddHeader("content-disposition", "inline;filename=abc.doc");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
       
        gridinfo.RenderControl(htw);
        Response.Write(sw.ToString());

        Response.Flush();
        Response.End();
    }
}

I am getting the following error
Message="Control 'ctl00_Main_gridinfo' of type 'GridView' must be placed inside a form tag with runat=server." Source="System.Web"
What is the problem and likely solution
0
Comment
Question by:smanthanims
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 500 total points
ID: 38773338
You are missing the Code to verify the Render Control

public override void
   VerifyRenderingInServerForm(Control control)
{
   return;
}

The Complete Code Looks Like Somthing:

private void Page_Load(object sender, EventArgs e)
{
   System.IO.StringWriter stringWriter =
      new System.IO.StringWriter();
   System.Web.UI.HtmlTextWriter htmlWriter =
      new System.Web.UI.HtmlTextWriter(stringWriter);
   contentPanel.RenderControl(htmlWriter);
   string s = stringWriter.ToString();
   Response.Write(s);
   Response.End();
}

public override void
   VerifyRenderingInServerForm(Control control)
{
   return;
}

Reference:
http://forums.asp.net/t/1016960.aspx/1?Problem%20with%20GridView%20s%20RenderControl
0
 
LVL 8

Expert Comment

by:deepu chandran
ID: 38773383
Hi,

The error message looks like you are mssing runat="server2 on your form tag ot <form sunat="server"> itself is missing

-- Deepu
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question