Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2009, 12:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Question 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>
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================

Last edited by rodmcleay; October 28th, 2009 at 02:16 AM..
 
Old October 28th, 2009, 08:37 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default 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.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old October 28th, 2009, 12:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old October 28th, 2009, 01:10 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default 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.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old October 28th, 2009, 01:25 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default 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.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old October 28th, 2009, 01:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 28th, 2009, 02:06 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Cool

Thanks Imar I guess I was mistaken! Learn something new everyday.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old October 28th, 2009, 02:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Thanks Imar,
I'll check out those resources.
Rod
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
image and fileupload control bond007 ASP.NET 2.0 Basics 0 April 28th, 2009 12:30 AM
fileupload control - disable input PeterPeiGuo ASP.NET 3.5 Professionals 1 January 6th, 2009 07:01 PM
Access denied error when using FileUpload Control mii2029 ASP.NET 3.5 Basics 0 October 25th, 2008 05:45 PM
FileUpload control aliirfan84 ASP.NET 2.0 Professional 1 June 2nd, 2007 03:37 PM
FileUpload Control MunishBhatia ASP.NET 2.0 Basics 2 December 6th, 2006 04:03 AM





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