Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 28th, 2009, 12:52 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
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..
  #2 (permalink)  
Old October 28th, 2009, 08:37 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
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
  #3 (permalink)  
Old October 28th, 2009, 12:58 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
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
======================================
  #4 (permalink)  
Old October 28th, 2009, 01:10 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
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
  #5 (permalink)  
Old October 28th, 2009, 01:25 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
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
  #6 (permalink)  
Old October 28th, 2009, 01:52 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
  #7 (permalink)  
Old October 28th, 2009, 02:06 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
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
  #8 (permalink)  
Old October 28th, 2009, 02:24 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
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
======================================
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



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


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