Hi ,
I am Using Update Panel in my page and this Update panel contains lots of server side controls including GridView ...
Well, i want to Export Data from GridView to Excel or PDF file ... But its not working properly ...
The Code is ...
Response.Clear();
Response.AddHeader("content-disposition","attachement;filename=" +"IFR" + System.DateTime.Now +".xls");Response.Charset ="";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType ="application/vnd.xls";StringWriter stringWrite =newStringWriter();
HtmlTextWriter htmlWrite =newHtmlTextWriter(stringWrite);gvReport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
The code written is correct but it gives Exception on Execeting the line.. gvReport.RenderControl(htmlWrite);
Exception = < Control 'gvReport' of type 'GridView' must be placed inside a form tag with runat=server. >
And all the controls including GridView are inside the form tag.
Please Help me out to fix that problem i shall be very thankful 2 u.
Its gud if u reply the solution on ... irfan623@dotnet.itags.org.hotmail.com
Thanks .
Irfan Gull
Hi There,
You can't use Response.Write inside of an UpdatePanel.
Why? Because Ajax updates are done using XMLHttpRequest which exchanges xml with server. Resonse.Write adds some string in xml and the xml parser on the client has no idea what to do with such a xml.
Hope it helps!
Basically the Error is at
dgFailureReport.RenderControl(htmlWrite);
When this line executes than Exception occurs...
There is no problem with response.write ...
the problem is with only the above one line code...
Let me paste the code again here... am still having that problem please someone help me ragarding this... thanks in advance...
Response.Clear();
Response.AddHeader("Internal Failure Report","attachement;filename=" +"IFR" + System.DateTime.Now+".xls");Response.Charset ="";
Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.ContentType ="application/vnd.xls";
StringWriter stringWrite =newStringWriter();HtmlTextWriter htmlWrite =newHtmlTextWriter(stringWrite);dgFailureReport.RenderControl(htmlWrite); // Here Exception Occurs.
Response.Write(stringWrite.ToString());
Response.End();
No comments:
Post a Comment