Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

styling the asp:fileupload control

I have a file upload control in asp.net like so:

<asp:FileUpload ID="File1" runat="server" Font-Size="Small" Width="100%" />  

For some reason the Browse... button does not apply the standard CSS that I have applied to any input[type="button"] controls.

How can I apply the same CSS to the Browse button of that control?

like image 424
sd_dracula Avatar asked Feb 13 '23 13:02

sd_dracula


2 Answers

try this

<input type="file" class="hidden" id="uploadFile"/>
<div class="button" id="uploadTrigger">Browse</div>

some css

.hidden {
    display:none;
}
.button {
    border: 1px solid #333;
    padding: 10px;
    margin: 5px;
    background: #777;
    color: #fff;
    width:75px;
}

JS

$("#uploadTrigger").click(function(){
   $("#uploadFile").click();
});

Demo

like image 157
santosh singh Avatar answered Feb 16 '23 03:02

santosh singh


Since the OP was about ASP.NET and the accepted answer was HTML / javascript, I thought I'd answer it in ASP.NET terms:

ASP.NET portion:

<asp:FileUpload ID="fileUpload" runat="server" style="display:none" /> <input type="button" value="Select your file" id="browse"></input>

JQuery, with jQuery UI for .button() portion:

$("input:button").button(); ... $("#browse").click(function () { $("#<%= fileUpload.ClientID %>").click(); });

like image 27
Scott R. Frost Avatar answered Feb 16 '23 01:02

Scott R. Frost