---
title: "Dynamically loading image in Image control in ASP.NET"  
description: "Dynamically loading an image in Image control in ASP.NETHere In this Article, We will tell you how to add an   image in image control dynamically."  
author: "Anonymous User"  
published: 2011-02-25  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/478/dynamically-loading-image-in-image-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Dynamically loading image in Image control in ASP.NET

## Dynamically loading an image in Image control in ASP.NET

Here In this Article, We will tell you how to add an [image in image control](https://www.mindstick.com/articles/994/n-tier-architecture-in-asp-dot-net) dynamically.\

#### Steps to implement this task

##### Please follow the following steps to implement the desired task

- Add two aspx files in the project and give named as 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>&nbsp;        <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 the 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);              }        }
```

##### The output of the following code

![Dynamically loading image in Image control in ASP.NET](https://www.mindstick.com/mindstickarticle/c98d98d1-3186-4cac-9069-304b08a269d3/images/0fc14cb5-eb22-46dc-a8d6-1ade4b57a913.png)

##### After clicking Enter Image URL button following output will be displayed

![Dynamically loading image in Image control in ASP.NET](https://www.mindstick.com/mindstickarticle/c98d98d1-3186-4cac-9069-304b08a269d3/images/4577deba-3e44-43ee-8cb1-378a382b3c1c.png)

---

Original Source: https://www.mindstick.com/articles/478/dynamically-loading-image-in-image-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
