By default, the fileupload control does not support onchange events on the server side.
The onchange event of the client is used to call the _ dopostback method to use The onclick event of linkbutton to simulate an event triggering process.CodeAs follows:
Client:
<Asp: fileupload id = "fuphoto" onchange = "javascript :__ dopostback ('lbuploadphoto ','')"
Runat = "server" tooltip = "select image"/>
<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 a file from the 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;
}
}