Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net Ajax File upload
    primarykey
    data
    text
    <p>I am trying to upload an image and after uploading i want to show it in the image control. My code is:</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;/asp:ScriptManager&gt; &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt; &lt;ContentTemplate&gt; &lt;asp:FileUpload ID="FileUploadTest" runat="server" /&gt; &lt;asp:Button ID="ShowImage" runat="server" Text="Show" onclick="ShowImage_Click" /&gt; &lt;asp:Image ID="ImageUploaded" runat="server" Height="150px" Width="150px" ImageUrl="~/images/blankImage.gif" /&gt; &lt;asp:Label ID="Label1" runat="server" Text=""&gt;&lt;/asp:Label&gt; &lt;/ContentTemplate&gt; &lt;Triggers&gt; &lt;asp:PostBackTrigger ControlID="ShowImage" /&gt; &lt;/Triggers&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>C# code is:</p> <pre><code>protected void ShowImage_Click(object sender, EventArgs e) { Label1.Text = ""; if (FileUploadTest.HasFile) { try { if (FileUploadTest.PostedFile.ContentType == "image/jpeg") { if (FileUploadTest.PostedFile.ContentLength &lt; 102400) { string filename = Path.GetFileName(FileUploadTest.FileName); string imageSavePath = Server.MapPath("~/images/") + filename; FileUploadTest.SaveAs(imageSavePath); ImageUploaded.ImageUrl = imageSavePath; ImageUploaded.Visible = true; Label1.Text = "Upload status: File uploaded!"; } else Label1.Text = "Upload status: The file has to be less than 100 kb!"; } else Label1.Text = "Upload status: Only JPEG files are accepted!"; } catch (Exception ex) { Label1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } else { Label1.Text = "No File !!!"; } } </code></pre> <p>But After pressing the show button, the image is uploaded successfully. But the image control got vanished. Can any one help me about it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload