C# .NET - how to show image in asp.net image control using ajax without refresh

Asked By Giri s on 29-Jun-12 06:09 AM
in my create user profile using file upload option upload image file and show that image in image control using ajax without refreshing the page...

and then resize that image before going to show  because my image control size is 400x400...

how to do this???please tel friends

Jitendra Faye replied to Giri s on 29-Jun-12 06:23 AM
Follow this link-

http://steptodotnet.blogspot.in/2012/01/preview-image-after-uploading.html

Here you will get example-
Giri s replied to Jitendra Faye on 29-Jun-12 06:28 AM
is there possible do this in asp:fileupload option friend????
Giri s replied to Jitendra Faye on 29-Jun-12 07:29 AM

i cannot access AsyncFileUpload 

protected void AsyncFileUpload1_UploadedComplete1(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{

User objUser = new User();

string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);

HttpPostedFile pf = AsyncFileUpload1.PostedFile;

System.Drawing.Image img2 = System.Drawing.Image.FromStream(pf.InputStream);

System.Drawing.Image bmp2 = img2.GetThumbnailImage(200, 200, null, IntPtr.Zero);

// Imagename = objUser.UserID + filename;
Imagename = filename;
Imagepath = "D:\\ShopMonkey_WebApp_29062012\\ShopMonkey_WebApp\\ShopMonkey\\Images\\" + Imagename;
bmp2.Save(Path.Combine(@"D:\ShopMonkey_WebApp_29062012\ShopMonkey_WebApp\ShopMonkey\Images\", Imagename));

objUser.UploadImagePath = Imagepath;

objUser.UploadImagename = Imagename;

System.Drawing.Image img1 = System.Drawing.Image.FromFile(Imagepath);

System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);
ThumbNailPath = "D:\\ShopMonkey_WebApp_29062012\\ShopMonkey_WebApp\\ShopMonkey\\ThumbNails\\" + Imagename;
bmp1.Save(Path.Combine(@"D:\ShopMonkey_WebApp_29062012\ShopMonkey_WebApp\ShopMonkey\ThumbNails\", Imagename));

objUser.UploadThumbnailPath = ThumbNailPath;
//Check_Pin(objUser);

Img_Show.ImageUrl = objUser.UploadImagePath;

}

it wont show image...i cannot access able AsyncFileUpload1_UploadedComplete1..it checks the loop and out from that loop..

i already add reference ajax dll in my project..another that have to add any dll???

can u please anyone tel solution for this friend????

dipa ahuja replied to Giri s on 29-Jun-12 08:17 AM


<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
  <asp:FileUpload ID="FileUpload2" runat="server"></asp:FileUpload>
  <asp:Button ID="btnUplopad" Text="Upload file" OnClick="btnUplopad_Click" runat="server" />
</ContentTemplate>
<Triggers>
  <cc1:PostBackTrigger ControlID="btnUplopad" />
</Triggers>
</asp:UpdatePanel>

 
 protected void btnUplopad_Click(object sender, EventArgs e)
  {
  if (FileUpload2.HasFile)
  {
    string path = Server.MapPath("~/images/") + FileUpload2.PostedFile.FileName; ;
    FileUpload2.SaveAs(path);
    Image1.ImageUrl = path;
  }
  else
  {
    UploadStatusLabel.Text = "You did not specify a file to upload.";
  }
  }
 
 
Giri s replied to dipa ahuja on 29-Jun-12 08:31 AM
it not show the image and after come out from the loop it goes to asseembly page..
and it show error like this

Disassembly cannot be displayed in run mode

with a link like 

AjaxControlToolkit.AsyncFileUpload.OnUploadedComplete(AjaxControlToolkit.AsyncFileUploadEventArgs)

how to clear this friend
Super Man replied to Giri s on 29-Jun-12 02:39 PM
have you added AJAx fileupload control into your page.

If yes , check the name of it. Is it "AsyncFileUpload1"

Hope it will solve your problem