The fileupload control is verified in client JS, and only the specified file type is allowed.

Source: Internet
Author: User
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<Html xmlns = "http://www.w3.org/1999/xhtml ">
<Head runat = "server">
<Title> No title page </title>
<Script type = "text/javascript" language = "javascript">

Function CheckFileType ()
{
Var objButton = document. getElementById ("Button1"); // upload button
Var objFileUpload = document. getElementById ('fileupload1'); // FileUpload
Var objMSG = document. getElementById ('msg '); // The DIV used to display the prompt information
Var FileName = new String (objFileUpload. value); // file name
Var extension = new String (FileName. substring (FileName. lastIndexOf (".") + 1, FileName. length); // File extension

If (extension = "jpg" | extension = "JPG") // you can add an extension.
{
ObjButton. disabled = false; // enable the upload button
ObjMSG. innerHTML = "";
}
Else
{
ObjButton. disabled = true; // disable the upload button
ObjMSG. innerHTML = "select the correct file ";
}
}


</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Div id = "msg"> </div>
<Asp: Button ID = "Button1" runat = "server" Text = "Upload" Enabled = "False"/>
<Br/>
<Asp: FileUpload ID = "FileUpload1" runat = "server" onChange = "javascript: CheckFileType ();"/>

</Div>
</Form>
</Body>
</Html>

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.