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. when page refresh happen Fileupload control get cleared.

when page refresh happen Fileupload control get cleared.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netvisual-studiohelptutorial
12 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.
  • C Offline
    C Offline
    chakran
    wrote on last edited by
    #1

    Hi, I am using fileupload control in asp.net. am selecting the file using browse button of file upload control. But due to postback event of any other control on the page the content(file path) of the fileupload textbox gets cleared... Viewstate is enabled to this control. How to solve this problem??? am using vs 2008 and c#...

    D A 2 Replies Last reply
    0
    • C chakran

      Hi, I am using fileupload control in asp.net. am selecting the file using browse button of file upload control. But due to postback event of any other control on the page the content(file path) of the fileupload textbox gets cleared... Viewstate is enabled to this control. How to solve this problem??? am using vs 2008 and c#...

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      I believe that is default behaviour. You can retain the text through doing partial postback using update panel. Do not send upload control while doing the postback and it should retian the value.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      C 1 Reply Last reply
      0
      • D dan sh

        I believe that is default behaviour. You can retain the text through doing partial postback using update panel. Do not send upload control while doing the postback and it should retian the value.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        C Offline
        C Offline
        chakran
        wrote on last edited by
        #3

        I tried like this but not working. Just I placed scriptmanager and updatepanel on the page and kept the fileupload control inside updatepanel... Have I followed correctly???

        D 1 Reply Last reply
        0
        • C chakran

          I tried like this but not working. Just I placed scriptmanager and updatepanel on the page and kept the fileupload control inside updatepanel... Have I followed correctly???

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Wait a minute, were you referring to postback caused by clicking upload button or some other control? If you mean after clicking on upload button, I guess it is not possible. Also, AFAIK, you cannot set the text of te textbox in the control so you cannot even keep the file path somewhere and just set it. If you were referring to some other control which is causing postback, then keep just that control in the update panel and not the upload control.

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          1 Reply Last reply
          0
          • C chakran

            Hi, I am using fileupload control in asp.net. am selecting the file using browse button of file upload control. But due to postback event of any other control on the page the content(file path) of the fileupload textbox gets cleared... Viewstate is enabled to this control. How to solve this problem??? am using vs 2008 and c#...

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            Well... Html file control is very restrictive control. You cannot set value of file upload using javascript. You can only set using Browse Button. Now when the page is posted back, the whole page is sent to the server, server processes it and rewrites the whole page to the response and which is written over the browser(client). Thus if you select a file and some other button makes the postback, dont hesitate to save the file to the server as, the path, if not saved to the server, cant be shown in the file control at any case. Otherwise you can show a popup (preferably using window.open) to upload files and do the upload immediately after user selects the file. :rose:

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Simplify Code Using NDepend
            Basics of Bing Search API using .NET
            Microsoft Bing MAP using Javascript

            C 1 Reply Last reply
            0
            • A Abhishek Sur

              Well... Html file control is very restrictive control. You cannot set value of file upload using javascript. You can only set using Browse Button. Now when the page is posted back, the whole page is sent to the server, server processes it and rewrites the whole page to the response and which is written over the browser(client). Thus if you select a file and some other button makes the postback, dont hesitate to save the file to the server as, the path, if not saved to the server, cant be shown in the file control at any case. Otherwise you can show a popup (preferably using window.open) to upload files and do the upload immediately after user selects the file. :rose:

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Simplify Code Using NDepend
              Basics of Bing Search API using .NET
              Microsoft Bing MAP using Javascript

              C Offline
              C Offline
              chakran
              wrote on last edited by
              #6

              How to save and assign to the fileupload control? am trying to assign the path like this FileUpload1.PostedFile.FileName = "Path"; but getting error "Property or indexer 'System.Web.UI.WebControls.FileUpload.FileName' cannot be assigned to -- it is read only. any idea??

              M A 2 Replies Last reply
              0
              • C chakran

                How to save and assign to the fileupload control? am trying to assign the path like this FileUpload1.PostedFile.FileName = "Path"; but getting error "Property or indexer 'System.Web.UI.WebControls.FileUpload.FileName' cannot be assigned to -- it is read only. any idea??

                M Offline
                M Offline
                m dhu
                wrote on last edited by
                #7

                save path in any string/contol... for label control...

                label.text=File1.PostedFile.FileName;

                C 1 Reply Last reply
                0
                • M m dhu

                  save path in any string/contol... for label control...

                  label.text=File1.PostedFile.FileName;

                  C Offline
                  C Offline
                  chakran
                  wrote on last edited by
                  #8

                  but how to assign string value to fileupload control... I tried but got error messages... pls see my previous post...

                  D 1 Reply Last reply
                  0
                  • C chakran

                    but how to assign string value to fileupload control... I tried but got error messages... pls see my previous post...

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #9

                    You cannot as I told you. Fileupload should be the last thing to do in a page. Or else, have a listbox/listview (in case of multiple file upload) or a label with remove button or something in your page. That should work. Something like what we get in Gmail or outlook.

                    50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

                    1 Reply Last reply
                    0
                    • C chakran

                      How to save and assign to the fileupload control? am trying to assign the path like this FileUpload1.PostedFile.FileName = "Path"; but getting error "Property or indexer 'System.Web.UI.WebControls.FileUpload.FileName' cannot be assigned to -- it is read only. any idea??

                      A Offline
                      A Offline
                      Abhishek Sur
                      wrote on last edited by
                      #10

                      You cant do that ... Even ASP.NET cant do this, thus it cant retain its value during postbacks.. Sorry.. You need to store it in server as soon as you find it in server. And then show the message, file uploaded successfully.. .or so... ;)

                      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                      My Latest Articles-->** Simplify Code Using NDepend
                      Basics of Bing Search API using .NET
                      Microsoft Bing MAP using Javascript

                      C 1 Reply Last reply
                      0
                      • A Abhishek Sur

                        You cant do that ... Even ASP.NET cant do this, thus it cant retain its value during postbacks.. Sorry.. You need to store it in server as soon as you find it in server. And then show the message, file uploaded successfully.. .or so... ;)

                        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                        My Latest Articles-->** Simplify Code Using NDepend
                        Basics of Bing Search API using .NET
                        Microsoft Bing MAP using Javascript

                        C Offline
                        C Offline
                        chakran
                        wrote on last edited by
                        #11

                        still confusing.. How to store(session or any string variable) and assign to to fileupload control...

                        A 1 Reply Last reply
                        0
                        • C chakran

                          still confusing.. How to store(session or any string variable) and assign to to fileupload control...

                          A Offline
                          A Offline
                          Abhishek Sur
                          wrote on last edited by
                          #12

                          As I already told you, even if you set the value of a FileUpload control, it cant assign the appropriate file pointer to the browser. So dont try to do this, rather when user choose the file, upload to the server immediately and work from the file placed in the server. Cheers. :rose:

                          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                          My Latest Articles-->** Simplify Code Using NDepend
                          Basics of Bing Search API using .NET
                          Microsoft Bing MAP using Javascript

                          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