Results 1 to 12 of 12

Thread: File upload filename still getting cleared!

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    File upload filename still getting cleared!

    Ok - we got a file upload control

    Code:
    <div style="text-align:center; vertical-align:middle"><asp:FileUpload ID="SourceFileUpload" EnableViewState="true" runat="server" /></div>
    It's got EnableViewState as true.

    And then this checkbox

    Code:
    <asp:CheckBox ID="StandardCheckBox" AutoPostBack="true" Text="Yes" EnableViewState="true" runat="server" /></div>
    And then this sub

    Code:
        Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles StandardCheckBox.CheckedChanged
            'FindControl("TransDead").Visible = False
            If StandardCheckBox.Checked Then
                TranslationDeadline.Text = "Standard Turnaround"
            Else
                If TranslationDeadline.Text = "Standard Turnaround" Then
                    TranslationDeadline.Text = ""
                End If
            End If
        End Sub
    If you browse for a filename prior to click this check box then when you click the check box the filename gets cleared.

    What is causing that?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: File upload filename still getting cleared!

    I should have mentioned that all of this is in an AJAX update panel.

    Is there a way to take the browser control out of the panel?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File upload filename still getting cleared!

    I have a feeling this is happening because you can't set a file upload HTML control text value from code, and I would imagine that includes viewstate as well.

    It is a security feature.

    Imagine you went to a website, and that site had a file upload component on it, and when you went to the website, it autofills in some important personal file from your computer into the textbox, and then submits the form via javascript. That would be a HUGE security flaw in the browser and would be exploited to no end.

    So as it stands, a value of an upload control should only be able to be set by the user. If a post back occurs, the value is lost when the page is reloaded. The code may even be trying to set the value back, but I believe the underlying HTML control that is being rendered in the end will simply not accept a value being set.

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: File upload filename still getting cleared!

    We kind of thought that - thus why we asked how to get the browse control out of the update panel.

    The problem we have is that the user must satisfy several selection before browsing and uploading.

    If they browse and then decide they really wanted to set a date as x/y/z then when they do such it clears the control.

    The only way around this otherwise would be to make all those "selection" items be JS and keep them client side - right?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File upload filename still getting cleared!

    Or disable the actual file selection until all selections have been made.

    Make it sort of like a 2 step process (even if its still all on 1 page)

    So once they make all selections, enable the file upload control so they can select a file. If at that point they go back and change something that forces a postback, they need to select the file again.

    You can obviously do this however it meets the needs of the specific app you are doing, but something along those lines will probably be needed.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: File upload filename still getting cleared!

    It's a partial postback, and yes, it's being cleared because the file browse button is inside the UpdatePanel. You will need to remove it, and you can do this by moving it out of the ContentTemplate for the UpdatePanel. Also keep in mind that the UpdatePanel doesn't work for File Upload controls (for uploading); only keep things in the UpdatePanel that need refreshing or can be affected by partial postbacks. There's no need to put everything in there.

  7. #7

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: File upload filename still getting cleared!

    Ok - here's a screen shot we just got from the client on how they want the page laid out.

    Click MORE and an additional text box for e-mail appears (up to 4)

    Hit the CALENDAR and a calendar control appears that will fill a date into the DEADLINE field.

    Click STANDARD TURNAROUND and words "STANDARD TURNAROUND" appear in the DEADLINE field.

    Click the GLOBE and a huge panel appears with all the languages or all the countries with check boxes - you can set all you want.

    Now you BROWSE - and UPLOAD - grid below fills with rows from the database about the upload that just occured.

    Where would you all use update panels and where would you use JS in all this?
    Attached Images Attached Images  

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: File upload filename still getting cleared!

    I'd replace the calendar with a proper javascript calendar control so that no postback or partial postback is required.

    If the globe does a partial postback, then I'd use an UpdatePanel just around it.

    And around the MORE link as well, giving you a total of two updatepanels.

  9. #9
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: File upload filename still getting cleared!

    Why not use Validators?

  10. #10

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: File upload filename still getting cleared!

    Quote Originally Posted by wey97 View Post
    Why not use Validators?
    And what is a validator?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: File upload filename still getting cleared!

    Validators are those controls in ASP.NET which do things like 'ensure field1 is filled out' or 'ensure field7 is a value greater than 35'.

  12. #12
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: File upload filename still getting cleared!

    Autopostback checkboxes (or anything autopostback) even on an update panel aren't a good idea IMO. If you use validators, you won't need to post back to see the check.
    Unfortunately, there is no validator to force a checkbox check but it's simple to write one using a custom validator. There are plenty of examples if you search.

    Just a word of warning, but update panels aren't the magic they're made out to be.
    http://msdn.microsoft.com/en-us/magazine/cc163413.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width