Page view counter

cannot maintain values of the file upload control after post back

Last post 01-30-2008 4:42 AM by mbm2006. 5 replies.

Sort Posts:

  • cannot maintain values of the file upload control after post back

    10-24-2007, 5:01 AM
    • Loading...
    • ameydesai
    • Joined on 10-24-2007, 8:50 AM
    • Posts 17
    • Points 2

    I have a user control and have 2 drop downs in it... when i select one of it ....on the indexchange of the first dropdown i populate the other drop down...and on the post back the file path tat i have selected disappears after post back.. 

  • Re: cannot maintain values of the file upload control after post back

    10-24-2007, 8:55 AM
    • Loading...
    • pradeep7n
    • Joined on 10-24-2007, 6:07 AM
    • Coimbatore, India
    • Posts 212
    • Points 1,244

    It is not possible to maintain values of the file upload control after post back.

    And even its not possible to rebind the value for codebehind on pageload. 

    Please remember to click "Mark as Answer" on this post if it helped you.
    Happy Coding Yes
    Pradeep
  • Re: cannot maintain values of the file upload control after post back

    10-24-2007, 9:42 AM
    • Loading...
    • mustakim
    • Joined on 05-17-2007, 6:43 AM
    • Posts 163
    • Points 1,044

    HI,

    we can't set value of file upload control after postback with codebehind and javascript. there is no such property to bind file upload control after postback.

    Regards

    Regards,

    Mustakim Mansuri (MCTS, MCPD)
    Cybage Software Pvt. Ltd.
  • Re: cannot maintain values of the file upload control after post back

    10-24-2007, 10:45 AM
    Answer
    • Loading...
    • anas
    • Joined on 09-21-2006, 8:31 AM
    • Ramallah, Palestine
    • Posts 6,114
    • Points 48,398
    • Moderator

    hi

    there is no direct solutions as mentioned .. until you use the ajax ..

    also you cant set the value of FileUpload control even from javascript

    and the following didnt worked even its rendered in html  :

    Me.FileUpload1.Attributes("value") ="...."
     solution:

    but you can use:

    •  label control to display the last selected file .
    • hiddenField Control to transfer the selected file from the client to server.

    but you need also to remeber the last posted file

    because in case you dont select a file from FileUpload control  after a postback and then submit ,

    the FileUpload.postedFile data will gone , so you have to save the posted file to the session ...

    this is how :

    asp.net page  Code:

     <form id="form1" runat="server">
             
            <asp:FileUpload ID="FileUpload1" runat="server" /> <br />
             <asp:Label ID="lblCurrentFile" runat="server"></asp:Label><br />
            <br />
            <asp:Button ID="BtnSubmit" runat="server" Text="postBack" />
            <br />
            <asp:HiddenField ID="HiddenField1" runat="server" />
        </form>

     codeBehind: 

    Private Property PostedFile() As HttpPostedFile
            Get
                If Me.Session("postedFile") IsNot Nothing Then
                    Return Session("postedFile")
                End If
                Return Nothing
            End Get
            Set(ByVal value As HttpPostedFile)
                Session("postedFile") = value
            End Set
        End Property
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            If Not IsPostBack Then
                Me.BtnSubmit.Attributes("onclick") = _
                String.Format("document.getElementById('{0}').value= document.getElementById('{1}').value;", _
                Me.HiddenField1.ClientID, Me.FileUpload1.ClientID)
            End If
    
    
            If Me.FileUpload1.PostedFile IsNot Nothing _
            AndAlso Me.FileUpload1.PostedFile.ContentLength > 0 Then
                Me.PostedFile = Me.FileUpload1.PostedFile
            End If
    
            If Me.HiddenField1.Value <> "" Then
                Me.lblCurrentFile.Text = Me.HiddenField1.Value
            End If
    
        End Sub
     
    regards,
    Regards,

    Anas Ghanem.


    Note:Please Don't hesitate to click "Alert Moderators" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

  • Re: cannot maintain values of the file upload control after post back

    10-25-2007, 11:57 PM
    • Loading...
    • ameydesai
    • Joined on 10-24-2007, 8:50 AM
    • Posts 17
    • Points 2

    Thanks alot for the help.

    Regards.

  • Re: cannot maintain values of the file upload control after post back

    01-30-2008, 4:42 AM
    • Loading...
    • mbm2006
    • Joined on 01-28-2008, 1:15 AM
    • Posts 2
    • Points 4

    what if i what to save that file using SaveAs....

    pls reply...

Page 1 of 1 (6 items)