Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to display file upload control as a simple button(but not with textbox and button) upon clicking
it should display the file dialouge asusually. after selecting the file and clicking on another button say
submit the posted filename should assign to a label.

Minal Shah.
Posted

Why not hide(visible false) the actual file upload control and bind its event to a simple button. Clicking of button would be like triggering the file upload control. I think, browse button should popup even if the control is hidden. Try out.

UPDATE: Yes, you can use display="none" on the control to hide it yet access it. Further, no need to override, the button event. Just trigger the fileUpload button click on click of simple button.
 
Share this answer
 
v2
Comments
Ankur\m/ 10-May-10 9:12am    
Setting the visibility of a control to false will not render html equivalent for the control. So don't set Visible=false rather use display: none CSS property.
Moreover button click of a FileUpload control is not available to the user. I don't know if you can override it's default behavior.
I guess its not possible to hide the textbox in normal way.

Some options that may work,

1.Try javascript or CSS.
2.Try to develop a custom control.
3.Use some third party controls.
 
Share this answer
 
The FileUpload control is rendered as
XML
<input type="file" />

So it will be always like a TextBox + Button. CSS cannot change the basic look of a control.

The only way I see to achieve the requirement is:
You need to use ActiveX controls and Javascript to popup a FileDialogBox on click of the button and get the selected file name.

I am not very sure if this would be all.
You may search Google for "opening file dialog using javascript"
You may also take some help from this CodeProject article: An Open File Dialog in JavaScript[^]
Hope it gives you a good start for your research.
 
Share this answer
 
v2
HI,
You can customize the upload control using CSS
 
Share this answer
 
Comments
Ankur\m/ 10-May-10 9:13am    
And how?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900