1

I am trying to creage an image in ASP. I have tried this code but it does not work:

Image img;

protected void Page_Load(object sender, EventArgs e)
{
    img = new Image();
    img.ImageUrl = "~/images/numbersHorizontal.png";
    img.ID = "img";
}
2
  • Do you want create an image control dynamically, or generate an image? Commented Nov 29, 2013 at 22:20
  • create an image control dynamically Commented Nov 29, 2013 at 22:21

1 Answer 1

3

Code to create image looks correct. The only part that is missing is to add newly created image to the page. Try adding this as a last line:

this.Controls.Add(img);
Sign up to request clarification or add additional context in comments.

1 Comment

@user2320928: Consider accept the answer (using green tick to the left).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.