<input type="file" id="hmFile" runat="server" />
$("#<%=hmFile.ClientID%>").live("change", function (e) {
var filename = document.getElementById("<%=hmFile.ClientID%>").value;
var exn = "";
var i = filename.lastIndexOf('.');
if (i !== -1) {
exn = filename.slice(i + 1);
}
if (exn !== "") {
if (CheckValidFile(exn)) { //CheckValidFile() function check whether the selected file is valid
//Bind selected image with control from server side
// __doPostBack("", document.getElementById("<%=hidImageID.ClientID%>").value);
// Or use ajax
}
else {
alert("Unable to process this photo. Please check your photo's format and try again.\n We support these photo formats: JPG, JPEG, GIF, PNG, and BMP");
}
}
});
..........................................................
function CheckValidFile(exn) {
var newext = exn.toLowerCase();
if (newext == "jpg" || newext == "bmp" || newext == "jpeg" || newext == "png" || newext == "gif") {
return true;
}
else {
return false;
}
}
..............................................
Use
__doPostBack("IMAGE",exn ); // A postback occurs when execute this line
In the Server side
if (IsPostBack)
{
string parameter = Request.Form["__EVENTTARGET"];
string argument = Request.Form["__EVENTARGUMENT"];
if (parameter == "IMAGE")
{
hmFile.PostedFile.SaveAs("../Image/Test."+argument ); //argument contain image extension
imgCtrl1.ImageUrl="../Image/Test."+argument ;
// Alternate Method, Use httphandler and bind ImageStream with image Controller
}
Thanks & Regards
Solimon Joseph
Shwetabansal888, if this helps please login to Mark As Answer. | Alert Moderator