p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 3.5 Professionals (http://p2p.wrox.com/forumdisplay.php?f=352)
-   -   Hiding FileUpload Control (http://p2p.wrox.com/showthread.php?t=76792)

rodmcleay October 28th, 2009 12:52 AM

Hiding FileUpload Control
 
Hi All,
for cosmetic reaons I need to hide the file upload control and just expose an image button.
This all seems fine, I have the image button that is firing the file upload control and the user can select the file.

Howver when a different button is clicked to submit the form the Fileupload box clears before the page posts back.
Correction: The file doesn't post back, it clears the file upload control and gives it focus, I have to press the submit button again to post back, but the file has gone by then.

If I dont use the image button to load hte fileupload and show use the regular Browse button, the form submit button works correctly.

Why would an asp:imagebutton clear the fileupload control?
It should it even know it is there?

Any assistance would be greatly appreciated.

Regards,
Rod

Code:


<
asp:ImageButton
ID="ImageButton2"ImageUrl="/Interface/Images/UploadImagesLink.gif"
OnClientClick="triggerFileUpload();return false;"
runat="server"/>
<asp:ImageButtonID="ImageButton3"ImageUrl="/Interface/Images/EnterLink.gif"
runat="server"onclick="EnterImageButton_Click"/>
<asp:ButtonID="Button2"runat="server"onclick="Button1_Click"Text="Button"/>
 
<asp:FileUploadID="FileUpload2"runat="server"/>
<scripttype="text/javascript">
function triggerFileUpload() {
document.getElementById('<%= FileUpload1.ClientID.ToString() %>').click();
}
</script>


alliancejhall October 28th, 2009 08:37 AM

It's security...
 
You can't control the FileUpload from anything but the FileUpload. It's a security risk as far as the browser is concerned. It's the same reason why you can't style the browse button in the fileupload.

rodmcleay October 28th, 2009 12:58 PM

I am not changing the file upload, I am just raising the Browse button click event.
The issue is the the file upload is clearing and not posting when a seperate button on the form is submitted.

alliancejhall October 28th, 2009 01:10 PM

Same thing...
 
Samething as far as the browser is concerned. It's still a security risk. The fileupload control is a very delicate thing you have to use it just like it is.

alliancejhall October 28th, 2009 01:25 PM

What if...
 
You kinda of in a round about way hid it with some styling? perhaps place a div over the textfield part of the fileupload and just have the browse button visible? but again you can't style the browse button...

just a thought.

Imar October 28th, 2009 01:52 PM

Quote:

The fileupload control is a very delicate thing you have to use it just like it is.
Not entirely true. The delicate part is true, but you can work around it. Google's Gmail can, and so can Telerik's Upload control:

http://demos.telerik.com/aspnet-ajax...defaultcs.aspx

I don't have the definite answer on how to do it as I haven't tried it for a while, but it can be done.

You may find an answer in this old and long-running thread: http://p2p.wrox.com/search.php?searchid=170000

Cheers,

Imar

alliancejhall October 28th, 2009 02:06 PM

Cool
 
Thanks Imar I guess I was mistaken! Learn something new everyday.

rodmcleay October 28th, 2009 02:24 PM

Thanks Imar,
I'll check out those resources.
Rod


All times are GMT -4. The time now is 09:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.