Solved

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

Posted on 2013-01-13
2
390 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now