Postback not working in Sharepoint Web Part after GridView Excel Export
Recently I had been developing a web part which display data in gridview and then export the grid to excel using following code.
protected void ExportGridToExcel()
{
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=UserList.xls";
Page.Response.ClearContent();
Page.Response.AddHeader("content-disposition", attachment);
Page.Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(GridViewSiteDetails);
this.Controls.Add(form);
form.RenderControl(htextw);
Page.Response.Write(stw.ToString());
Page.Response.End();
}
But found that the export utility once called will disable other control to postback.
Then after some search over net I found the following solution.
Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.
To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:
<script type='text/javascript'>
_spOriginalFormAction=document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;
script>
Hope this helps.
Hi Dear,
ReplyDeleteIt's really Amazing...Thnaks for your help. Keep posting for such valuable things..
Waiting for your next issue solver blog.