In my codebehind, I set the display property of an asp.net control to none as follows;
fuDoc.Attributes("style") = "display:none;" 'fuDoc is a FileUpload control.
On my page, if the user wants to upload a document, they click on a link, which by using jQuery, I set the display property to 'block' by using .show() as follows;
$('#fuDoc').show();
I also tried;
$('#fuDoc').attr('style', 'display:block;');
now, on form submit, I need to check if the fuDoc is visible and if so, do the standard file upload process e.g. check .HasFile etc..
However, although the fuDoc control is set to display:block in HTML with no problem, the following asp.net code always produces True
If fuDoc.Attributes("style") = "display:none;" Then 'always results to true
What is the reason for this? Any help would be appreciated.
Note: the FileUpload control is NOT created dynamically.
Rather than relying on detecting whether or not the FileUpload is visible on the page, you could include a TextBox or HiddenField such as:
This control will be hidden on your page, storing the value of
0by default.Whenever you hide/show the file upload, change your code to also change this value:
When hiding:
Then in your code-behind on post back, simply check: