Groups | Blog | Home
all groups > asp.net webcontrols > february 2005 >

asp.net webcontrols : Save state when create image


Mango
2/28/2005 3:51:32 AM
Hi there, I will be very happy if someone helps me. I need to create dynamic
image, and save the state between the postback. I mean I've got 5 buttons
and when I click on one of them, the image is creted with:

System.Web.UI.WebControls.Image Img1 = new
System.Web.UI.WebControls.Image();

Img1.ImageUrl = newPath;

Panel1.Controls.Add(Img1);

That's work fine but when I click on some of the other buttons I lost the
Image.

I tried this:

System.Web.UI.WebControls.Image Img1 = new
System.Web.UI.WebControls.Image();

Panel1.Controls.Add(Img1);

Img1.ImageUrl = newPath;

But it does not help me. I cant use OnInit, so the only way which I know is
to add image in design time and do it with Panel1.visible=false ,but I am
looking for more intelligent way to do it.

Any idea?





Wilco Bauwer
2/28/2005 9:37:24 AM
Controls are added to the current request _only_. After a postback, you
have to ensure that any controls you manually added before, should be
manually added again.

Take a look at http://wilcoding.xs4all.nl/Wilco/View.aspx?NewsID=147.
In this post I also describe your problem an a possible solution.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl
AddThis Social Bookmark Button