Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Viewstate not updated after TransmitFile

Viewstate not updated after TransmitFile

Scheduled Pinned Locked Moved ASP.NET
helpsysadmintutorialquestionannouncement
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KittyKit
    wrote on last edited by
    #1

    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

    Y P T K 4 Replies Last reply
    0
    • K KittyKit

      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

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      You may want to read this msdn[^] article about view states. You may have to override the SaveViewState() method on the page and set the value to null. Don't forget to call the base.SaveViewState() through!

      Yusuf May I help you?

      1 Reply Last reply
      0
      • K KittyKit

        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

        P Offline
        P Offline
        Prosanta Kundu online
        wrote on last edited by
        #3

        Try this

        HttpContext.Current.Response.TransmitFile(Server.MapPath("App_data/" + Viewstate["FileName"]));
        Viewstate["FileName"] = "";
        HttpContext.Current.Response.Flush();

        1 Reply Last reply
        0
        • K KittyKit

          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

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • K KittyKit

            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

            K Offline
            K Offline
            KittyKit
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups