Dynamically loading image in Image control in ASP.NET
In this demonstration we tell you that how to add images in image control
dynamically.
Steps to implement this task
Please follow the following steps to implement desire task
Ø
Add two aspx file in project and give named as like Default.aspx and
DynamicImage.aspx.
Ø
Write down following aspx script code to design user interface on Default aspx.
<div style="height: 486px; width: 872px">
<asp:Image
ID="Image1"
runat="server"
Height="432px"
Width="866px"
/>
<br
/>
<asp:TextBox
ID="TextBox1"
runat="server"
style="margin-left:
26px; margin-top: 17px" Width="183px"></asp:TextBox>
<asp:Button
ID="Button1"
runat="server"
onclick="Button1_Click"
style="margin-left:
21px; margin-top: 15px" Text="Enter Image URL"
Width="136px"
/>
</div>
Ø
At the click event of Button1 writes down following code.
Image1.ImageUrl =
"DynamicImage.aspx?path=" + TextBox1.Text;
Ø
At the load event of DynamicImage.aspx write down the following code
protected void
Page_Load(object sender,
EventArgs e)
{
string path = Request.QueryString[0];
if (path != null)
{
System.Drawing.Bitmap img =
new System.Drawing.Bitmap(path);
img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
Output of the following code
After clicking Enter Image URL button following output will be displayed

|