Viewstate not updated after TransmitFile
-
Hello there I have been spending almost half-a-day to get this problem solved, but could not even find a single article that would help me. I wonder whether nobody else has faced this problem. Okay, my webpage involves creating excel files. My download button has code like this HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=clientcopy.xlsx"); HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"])); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); Alright. this works fine. The problem is, After downloading I want to make Viewstate["FileName"] to be null. But whatever I do, during the next post back after the filetransmit, the Viewstate["FileName"] still retains the old value and refuses to get updated to null. I tried writing the Viewstate["FileName"] = null; at every possible place in the above code - at the begining, in the middle and at the end after response.end(). BUT no way :(( Can someone help on how to modify the viewstate after a file transmit??? Note: ===== My webpage has an update panel. Button "GO" displays a report in the update panel based on some selections outside the updatepanel. Button "ADD" keeps on adding the displayed reports to an excelfile until Button "download" is clicked and excelfile is downloaded. "GO" and "ADD" triggers partial postback and "download" triggers fullpostback. thanks Kit
-
Hello there I have been spending almost half-a-day to get this problem solved, but could not even find a single article that would help me. I wonder whether nobody else has faced this problem. Okay, my webpage involves creating excel files. My download button has code like this HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=clientcopy.xlsx"); HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"])); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); Alright. this works fine. The problem is, After downloading I want to make Viewstate["FileName"] to be null. But whatever I do, during the next post back after the filetransmit, the Viewstate["FileName"] still retains the old value and refuses to get updated to null. I tried writing the Viewstate["FileName"] = null; at every possible place in the above code - at the begining, in the middle and at the end after response.end(). BUT no way :(( Can someone help on how to modify the viewstate after a file transmit??? Note: ===== My webpage has an update panel. Button "GO" displays a report in the update panel based on some selections outside the updatepanel. Button "ADD" keeps on adding the displayed reports to an excelfile until Button "download" is clicked and excelfile is downloaded. "GO" and "ADD" triggers partial postback and "download" triggers fullpostback. thanks Kit
-
Hello there I have been spending almost half-a-day to get this problem solved, but could not even find a single article that would help me. I wonder whether nobody else has faced this problem. Okay, my webpage involves creating excel files. My download button has code like this HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=clientcopy.xlsx"); HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"])); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); Alright. this works fine. The problem is, After downloading I want to make Viewstate["FileName"] to be null. But whatever I do, during the next post back after the filetransmit, the Viewstate["FileName"] still retains the old value and refuses to get updated to null. I tried writing the Viewstate["FileName"] = null; at every possible place in the above code - at the begining, in the middle and at the end after response.end(). BUT no way :(( Can someone help on how to modify the viewstate after a file transmit??? Note: ===== My webpage has an update panel. Button "GO" displays a report in the update panel based on some selections outside the updatepanel. Button "ADD" keeps on adding the displayed reports to an excelfile until Button "download" is clicked and excelfile is downloaded. "GO" and "ADD" triggers partial postback and "download" triggers fullpostback. thanks Kit
Try this
HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"]));
Viewstate["FileName"] = "";
HttpContext.Current.Response.Flush(); -
Hello there I have been spending almost half-a-day to get this problem solved, but could not even find a single article that would help me. I wonder whether nobody else has faced this problem. Okay, my webpage involves creating excel files. My download button has code like this HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=clientcopy.xlsx"); HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"])); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); Alright. this works fine. The problem is, After downloading I want to make Viewstate["FileName"] to be null. But whatever I do, during the next post back after the filetransmit, the Viewstate["FileName"] still retains the old value and refuses to get updated to null. I tried writing the Viewstate["FileName"] = null; at every possible place in the above code - at the begining, in the middle and at the end after response.end(). BUT no way :(( Can someone help on how to modify the viewstate after a file transmit??? Note: ===== My webpage has an update panel. Button "GO" displays a report in the update panel based on some selections outside the updatepanel. Button "ADD" keeps on adding the displayed reports to an excelfile until Button "download" is clicked and excelfile is downloaded. "GO" and "ADD" triggers partial postback and "download" triggers fullpostback. thanks Kit
ViewState is the state of the "View", or in other words the state of the page displayed in the browser. Since the transmission of the file doesn't change that view it wouldn't change the ViewState. If you want something that can be changed with the file transmission you need to use a data location that can be affected by it. I suggest setting a cookie.
-
Hello there I have been spending almost half-a-day to get this problem solved, but could not even find a single article that would help me. I wonder whether nobody else has faced this problem. Okay, my webpage involves creating excel files. My download button has code like this HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=clientcopy.xlsx"); HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"])); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); Alright. this works fine. The problem is, After downloading I want to make Viewstate["FileName"] to be null. But whatever I do, during the next post back after the filetransmit, the Viewstate["FileName"] still retains the old value and refuses to get updated to null. I tried writing the Viewstate["FileName"] = null; at every possible place in the above code - at the begining, in the middle and at the end after response.end(). BUT no way :(( Can someone help on how to modify the viewstate after a file transmit??? Note: ===== My webpage has an update panel. Button "GO" displays a report in the update panel based on some selections outside the updatepanel. Button "ADD" keeps on adding the displayed reports to an excelfile until Button "download" is clicked and excelfile is downloaded. "GO" and "ADD" triggers partial postback and "download" triggers fullpostback. thanks Kit
Thanks for the replies, guys. @Yusuf: The link seems to be really good and informative. will go thro it. thanks. As a quick try, I tried overriding the SaveViewstate function. But that didnt help. @Prosanta: It didnt work either. As I mentioned earlier I had placed the code at every possible location @Gray: I think i will try storing it in the session. What say? Cheers Kit