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".
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.
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.
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.
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.