ASPNET uses FileUpload control to implement popup selection file feature

Source: Internet
Author: User

Because the recent project needs just contact with ASPNET, the pop-up function in the FileUpload control in the ASPNET is encountered in the context of the need for a client popup dialog box, without knowing what third-party controls are. The whole process has some curve meaning of saving the nation.

Overall idea:

Hide FileUpload, button Two ASP controls, the input button to trigger the FileUpload click event, and then through the FileUpload onchange event triggers the button's Click event, invoke the background code.



<asp:fileupload clientidmode= "Static" id= "FileUpload1" runat= "Server" onchange= "document.getElementById" (' Button2 '). Click (); style= "Visibility:hidden"/>
<input id= "Button1" button "type=" Select File "value=" button "  class=" document.getElementById (' FileUpload1 '). Click () "/> <asp:button id=" Button2 "clientidmode="
Static "runat= "Server" style= "Visibility:hidden" text= "button" onclick= "Button1_click_test"/>


Follow up business operations in background events

protected void Button1_click_test (object sender, EventArgs e)
{
<span style= "White-space:pre" >	</span>response.write ("<script>alert (' Test ') </script>");
<span style= "White-space:pre" >	</span>//Operations on files Fileupload1.filename
}

When you use document.getElementById to get an ASP control, you use control Id.clientid to discover that sometimes you can't get specific controls, and here I set ClientIDMode as static and use the control ID number directly as a way to find it. Also note that when you hide the control, you need to use style= "Visibility:hidden" If you set visible to False, the event cannot be triggered.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.