Vishal Mahajan

Vishal Mahajan

  • NA
  • 286
  • 2.6k

upload and display the img using AsyncFileUpload control

Dec 28 2013 6:35 AM
 When i use this code without master page Image is uploaded and display on screen but When i use to it with Master Page image uploaded but not display on webpage On upload compete Event
 
 
 
 
 
 
 
//html Code 
 <asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server">
</asp:ToolkitScriptManager>
 
<div id="divphoto">
<asp:UpdatePanel ID="UpdatePanel_photo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Image ID="imagesphoto" runat="server" Height="225px" Width="175px" BorderStyle="Solid"
BorderWidth="0" BorderColor="#d8d8d4"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
 
 
<asp:Image ID="imagesphoto" runat="server" Height="225px" Width="175px" BorderStyle="Solid"
BorderWidth="0" BorderColor="#d8d8d4"/>
 
 
 c# code 
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
 
 
 
 
 protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
Int32 id = Convert.ToInt32(Session["tempid"]);
string filename = AsyncFileUpload1.PostedFile.FileName;
string extension = filename.Substring(filename.LastIndexOf('.'));
if (int.Parse(e.FileSize)>150000)
{
string s = "File size must not exceed 150 KB";
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + s + "');</script>");
return;
}
if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg")
{
Bitmap originalBMP = new Bitmap(AsyncFileUpload1.FileContent);
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
string newfilename = "Photo_" + id + ".jpg";
//string filePath = Request.PhysicalApplicationPath + "upload\\" + newfilename;
string filePath = TEGlobal.uploadurl + newfilename;
//if (origWidth > 100 || origHeight > 130)
if (origWidth > 206 || origHeight > 260)
{
//Bitmap newBMP = resizeimage(originalBMP, origWidth, origHeight, 100, 130);
Bitmap newBMP = resizeimage(originalBMP, origWidth, origHeight, 206, 260);
newBMP.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
originalBMP.Dispose();
newBMP.Dispose();
}
else
{
AsyncFileUpload1.SaveAs(filePath);
}
string url = TEGlobal.downloadurl + newfilename + '?' + DateTime.Now.ToString("HH:MM:ss");
newpath = TEGlobal.downloadurl + newfilename + '?' + DateTime.Now.ToString("HH:MM:ss");
ScriptManager.RegisterClientScriptBlock(AsyncFileUpload1, AsyncFileUpload1.GetType(), "img", "top.document.getElementById('imagesphoto').src='" + url + "';", true);
objphoto.appid = id;
objphoto.photo = newfilename;
objupdown.UpdatePhoto(objphoto);
UpdatePanel_photo.Update();
}
else
{
string s = "Only JPG files are allowed";
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + s + "');</script>");
return;
}
}