protected void btnUploadImage_Click(object sender, EventArgs e) { try { if (Session["UserID"] != null) { ClsBAL obj = new ClsBAL(); byte[] imageByte = null; if (fuImage.HasFile) { HttpPostedFile postedFile = fuImage.PostedFile; imageByte = new byte[postedFile.ContentLength]; if (postedFile.ContentLength > 102400) { lblMsg.InnerHtml = "The size of image must be less than 100KB(102400 bytes)."; return; } postedFile.InputStream.Read(imageByte, 0, postedFile.ContentLength); } lblMsg.InnerHtml = obj.InsertAgentLogo(Convert.ToInt32(Session["UserID"].ToString()), imageByte); Image img = (Image)this.Master.FindControl("imgAgentLogo"); img.ImageUrl = imgAgentLogo.ImageUrl = "~/ActualImage.ashx?ID=" + Session["UserID"].ToString(); } } catch (Exception ex) { lblMsg.InnerHtml = ex.Message; throw; } }