Asp. NET FileUpload control does not support onchange events on the server side by default, this functionality can be implemented in a flexible way.
This needs to borrow the client's onchange event, call the __doPostBack method to simulate an event triggering process with LinkButton onclick event , the specific code is as follows:
Client:
<asp:fileupload id= "Fuphoto" onchange= javascript:__dopostback (' Lbuploadphoto ', ') "runat=" Server "ToolTip=" Select Picture "/>
<asp:linkbutton id=" Lbuploadphoto "runat=" Server "onclick=" Lbuploadphoto_click "></asp: Linkbutton>
Background code:
//automatic upload event protected void Lbuploadphoto_click (object sender, EventArgs e) {fileupload ()
;
///upload file from Control public void FileUpload () {if (Fuphoto.postedfile!= null && fuPhoto.PostedFile.ContentLength > 0) {String ext = System.IO.Path.GetExtension (fuPhoto.PostedFile.FileName).
ToLower (); if (ext!= ". jpg" && ext!= ". Jepg" && ext!= ". bmp" && ext!= ". gif") {return;} string filename
= "Image_" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ext;
String path = "./uploadphoto/" + filename;
FuPhoto.PostedFile.SaveAs (Server.MapPath (path)); Response.Redirect ("Imagecut.aspx?")
Picurl= "+ server.urlencode (path));
else {//do some thing;}}