2

I have an ImageButton and a FileUpload controls in a child page of a master page. I would like to achieve something like when user click on the ImageButton, the browse file window will pop-up like what we did when we click on the Browse button of the FileUpload control.

How can call the browse file window of the FileUpload control when i click on the ImageButton?

1 Answer 1

2

have you tried this?

<script>
function browse() {
    document.getElementById('<%= FileUpload1.ClientID %>').click();
}
</script>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="browse()"
    ImageUrl="http://stackoverflow.com/favicon.ico" />
Sign up to request clarification or add additional context in comments.

2 Comments

return error: "Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object". My controls are inside a child page, is that matter?
i believe not. try this instead, on Page_Load: ImageButton1.Attributes["onclick"] = string.Format("document.getElementById('{0}').click();", FileUpload1.ClientID);

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.