Asked by:
Create images in runtime/Dynamically

Question
-
User1716325940 posted
Hello
My problem is that I don't know how to create an image to my webpage dynamically. On my webpage, I have a dropdownbox with four options. Autoposback is enabled. Dependent on witch of the options is choosed I create a different amount of labels and textboxes. I also need to create an image, but i don't know how to do that.
This is how I create a label:Label_Dynamic[iCounter] = new Label(); Label_Dynamic[iCounter].ID = "Label_Dynamic" + System.Convert.ToString(iCounter); Label_Dynamic[iCounter].Text = "Week/Day for service:";
Label_Dynamic[iCounter].Style["Position"] = "Absolute";
Label_Dynamic[iCounter].Style["Color"] = "#cb0022";
Label_Dynamic[iCounter].Style["Font-Size"] = "10pt";
Label_Dynamic[iCounter].Style["Top"] = "" + (6 + (iOffsetCounter * 42)) + "px";
Label_Dynamic[iCounter].Style["Left"] = "0px";
Label_Dynamic[iCounter].Visible = true;
Panel_OnChangeType.Controls.Add(Label_Dynamic[iCounter]);
Is it possible to create a picture in a way like this? I tried 'new Image();' but it didn't work...Hope you can help me...
Thursday, January 24, 2008 7:06 AM
All replies
-
User312496708 posted
This article should help
http://www.exforsys.com/tutorials/asp.net-2.0/asp.net-dynamic-image-control.html
http://www.c-sharpcorner.com/UploadFile/nagryum/generateimages07062007075701AM/generateimages.aspx
Thursday, January 24, 2008 7:18 AM -
User-1426124666 posted
For a very basic example, have a look at the first piece of code in this article.
Thursday, January 24, 2008 7:24 AM -
User1716325940 posted
Thanks for the links...
I'll follow the articles and se if I can make it work...
//Thomas
Friday, January 25, 2008 2:58 AM -
User1716325940 posted
Sorry... I think you guys misunderstood me.
I've expressed myself wrong :-(
The thing is, that I don't want to 'Create' an image. I want is to place a small image on the page dynamically and have the oppotunity to remove it again.
I have an image in '~/Images/' called info.jpg - which I want to place on my page.
Friday, January 25, 2008 5:02 AM -
User-1426124666 posted
Oh, I see. In that case you will need to create a dynamic control when the page loads, e.g
Dim i As New Image
i.ImageURL = "path to image"
myPanel.Controls.Add(i)
Friday, January 25, 2008 5:08 AM -
User1716325940 posted
Isn't that only possible in Visual Basic? My code is C#
//Thomas
Oh, I see. In that case you will need to create a dynamic control when the page loads, e.g
Dim i As New Image
i.ImageURL = "path to image"
myPanel.Controls.Add(i)
Friday, January 25, 2008 7:23 AM -
User-1426124666 posted
Isn't that only possible in Visual Basic? My code is C#No, you can use exactly the same objects and methods in C#.Friday, January 25, 2008 7:32 AM -
User1716325940 posted
Hmm ok.
I'm sorry, but I don't know how to use it in C# then.
In your example there's no semicolons?
For the 'Dim' Visual Studio writes: "The type or namespace name 'Dim' could not be found (are you missing a using directive or an assembly reference?)"
//Thomas
Friday, January 25, 2008 8:03 AM -
User-1426124666 posted
C# simply has different syntax to VB.NET. For C#, it would be something like
Image i;
i.ImageURL = "path to image";
myPanel.Controls.Add[i];
Either way, my point wasn't to give you code that you can copy and paste. If you do this, you won't learn anything. What you should do, is look at the objects and methods that I mentioned, look them up in the help file and see how they can be used. This way you will understand what you are actually doing rather than just copying an answer from something you found on the internet.
Friday, January 25, 2008 8:14 AM -
User104627567 posted
if i m nt wrong u can try this...
Image img = new Image();
set the url for image
img.ImageUrl = "~/images/thumb-3.jpg";
img.Width = 120; //set the image width
img.Height = 100; //set the image hight
imageDiv.Controls.Add(img);Monday, July 20, 2009 11:00 PM