0

I'm trying to style an ASP.NET FileUpload control by hiding it and putting in my own controls. I'm doing this with jQuery:

$(function () {
    $('input[type=file]').each(function () {
        var fileUpload = $(this);

        var textBox = $('<input type="text">');
        textBox
            .css('width', fileUpload.width() - 85)
            .css('margin-right', 5)
            .prop('disabled', fileUpload.prop('disabled'));

        var button = $('<input type="button" value="Browse...">')
            .prop('disabled', fileUpload.prop('disabled'));

        fileUpload.change(function () {
            textBox.val(fileUpload.val());
        });

        button.click(function () {
            fileUpload.click();
        });

        fileUpload.after(button).after(textBox);
        fileUpload.hide();
    });
});

This basically works great, except that I need to click my submit button twice in IE (10). I can't reproduce this in jsFiddle, but I did make a stripped down ASP.NET project where it happens.

In Firefox, I don't have this problem. Anyone know where I can start to look?

2 Answers 2

0

Fabi's answer to this question solved it for me. Possibly, it's some sort of security feature, I'm not sure. But by using a label for the file upload, you only need to click the label once.

You will have to style the label as a button though. There's a great explanation in the jsFiddle. I'm not sure about the remark about Mozilla. It works fine in Firefox for me.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can't style FileUpload for security reasons in IE, plus the very little changes you can might be different looking in each browser.

A solution which is given me by a friend for my project is to hide the FileUpload and put some image over it. The concept is to give the FileUpload opacity 0 and zindex high and the button zindex low and position absolute.

Here is a code sample from our proj

.NewInvoiceDialog .AspFileUpload { cursor: pointer; position: absolute; z-index: 1; -moz-opacity: 0.00; opacity:.00; filter: alpha(opacity=00); }

.NewInvoiceDialog .stepBlueButtonWrapper.AddInvoiceFile { float: none; z-index:0; }

.NewInvoiceDialog .stepBlueButtonWrapper.AddInvoiceFile * { z-index:0; cursor:text; }

        <div style="position:relative; display:inline-block">
            <asp:FileUpload ID="fileUpload" CssClass="NewInvoiceDialog_AspFileUpload" runat="server" ClientIDMode="Static" />
            <div class="stepBlueButtonWrapper AddInvoiceFile">
                <a><span> בחר חשבונית </span></a>
            </div>
        </div>

1 Comment

Please read my question entirely. I know the tricks to style a file upload. It's some IE10 behavior I'm having trouble with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.