Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Launch Process with NOT as Administrator 15 67
Expando 4 36
Calling stored proc in EDMX 11 19
Birthdays 3 22
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now