Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-13
2
Medium Priority
?
407 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:Srinivas Mantha
[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:
Rahul Agarwal earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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