Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying css on asp.net FileUpload Control's Browse Button only

Tags:

c#

.net

css

asp.net

I have a FileUpload Control like this

<asp:FileUpload ID="fileuploader" runat="server" />

Now I want to apply css only on the Browse button part

alt text

How can I do this?

like image 928
Mohammad Nadeem Avatar asked Oct 11 '10 12:10

Mohammad Nadeem


People also ask

How do I restrict a file type in FileUpload control?

By default the FileUpload control doesn't have a property to restrict file types when the select file window is opened. However, you can check the file uploaded extension before continuing the process. Its simple. Get the extension of the file selected via FileUpload control using the below code.

How do I stop FileUpload control from clearing on postback?

The simple solution for preventing file loss from an upload control on postback is to put the upload control outside of an update panel control on a . aspx page. Or, in other words, put all the input controls that might trigger a postback inside an update panel.


2 Answers

Styling an input tag with type="file" requires a bit of work, browsers don't behave similarly when you try to style them unfortunately.

There are a few methods of doing so though:

  • http://www.quirksmode.org/dom/inputfile.html
  • http://www.appelsiini.net/projects/filestyle
like image 101
wsanville Avatar answered Sep 19 '22 08:09

wsanville


This is possible you can change the FileUpload control using following code.

Step 1: Change FileUpload control with this code on aspx page

<label class="file-upload">
    <span><strong>Upload Image</strong></span>
    <asp:FileUpload ID="FileUpload1" runat="server" >
    </asp:FileUpload>
</label>

Step 2: now add below CSS code into your main CSS file

.file-upload {
    display: inline-block;
    overflow: hidden;
    text-align: center;
    vertical-align: middle;
    font-family: Arial;
    border: 1px solid #124d77;
    background: #007dc1;
    color: #fff;
    border-radius: 6px;
    -moz-border-radius: 6px;
    cursor: pointer;
    text-shadow: #000 1px 1px 2px;
    -webkit-border-radius: 6px;
}

.file-upload:hover {
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1));
        background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%);
        background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%);
        background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%);
        background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%);
        background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0);
        background-color: #0061a7;
}

/* The button size */
.file-upload {
    height: 30px;
}

.file-upload, .file-upload span {
        width: 90px;
}

.file-upload input {
            top: 0;
            left: 0;
            margin: 0;
            font-size: 11px;
            font-weight: bold;
            /* Loses tab index in webkit if width is set to 0 */
            opacity: 0;
            filter: alpha(opacity=0);
}

.file-upload strong {
            font: normal 12px Tahoma,sans-serif;
            text-align: center;
            vertical-align: middle;
}

.file-upload span {
            top: 0;
            left: 0;
            display: inline-block;
            /* Adjust button text vertical alignment */
            padding-top: 5px;
}

It's done.

like image 31
Syed Faheem Abbas Avatar answered Sep 19 '22 08:09

Syed Faheem Abbas