1

I have a webpage containing one ASP.NET file upload control and a button to upload the file to server. The existing code looks like below.

<div runat="server" style="width: 110%">
  <asp:FileUpload ID="fileUpload" runat="server" />
  <asp:Button ID="BtnFileUpload" runat="server"           OnClick="BtnFileUpload_Click" Text="Upload" />               
</div>

But our client don't want to see the default look and feel of a standard file upload control. He wants us to add another button and wrap the file upload control with the button, so that whenever user clicks on the button, file upload dialog window opens.

Thanks

2 Answers 2

1

you cna do that using jquery you can set fileupload visiblity as none and can open fileuploader from button click like

<div runat="server" style="width: 110%">
    <asp:FileUpload style="display:none" ID="fileUpload" runat="server" />
    <asp:Button ID="BtnFileUpload" runat="server" onclick="$('#fileUpload').trigger('click'); return false;" OnClick="BtnFileUpload_Click" Text="Upload" />
</div>

you need to reference of jquery for this.

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

2 Comments

It didn't work for me.. I tried adding a button as <asp:Button Text="Browse.." runat="server" id="btnBrowse" OnClientClick ="$('#fileUpload').trigger('click'); return false;" /> but nothing is happening.
can you please check is there any javascript error in console
0

In addition to @Kevin Shah's solution, I got it working this way:

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="BtnFileUpload" runat="server" OnClientClick="$('#ContentPlaceHolder1_FileUpload1').trigger('click'); return false;" Text="Upload" />

My Webform is inside a MasterPage, so I had to look at "View source" while debugging in Chrome to get the correct element ID ContentPlaceHolder1_FileUpload1 instead of just FileUpload1

Comments

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.