How do I get rid of a usercontrol when I want to replace it withanother.

C

COHENMARVIN

I have some code like this:
Dim control As Control
control = Page.LoadControl("../usercontrols/
AlertsForQA.ascx")
content.Controls.Add(control)
'content' is the ID of a 'span' control. This is my way of adding
usercontrols to a aspx page.
Maybe there is a better way.
Anyway, I find that I want to get rid of the user control at some
point, and replace it with another user control. I could just do an
'Add' of the new control, but that would not unload or otherwise get
rid of the first control. Is there any way to get rid of the first
control? Should I save the 'control' that I first added in a session
variable so that I can somehow get rid of it later? Will the first
control simply be removed if I do a postback and neglect to add it in
page load?
Thanks,
Marv.
 
L

Lloyd Sheen

I have some code like this:
Dim control As Control
control = Page.LoadControl("../usercontrols/
AlertsForQA.ascx")
content.Controls.Add(control)
'content' is the ID of a 'span' control. This is my way of adding
usercontrols to a aspx page.
Maybe there is a better way.
Anyway, I find that I want to get rid of the user control at some
point, and replace it with another user control. I could just do an
'Add' of the new control, but that would not unload or otherwise get
rid of the first control. Is there any way to get rid of the first
control? Should I save the 'control' that I first added in a session
variable so that I can somehow get rid of it later? Will the first
control simply be removed if I do a postback and neglect to add it in
page load?
Thanks,
Marv.

When you do a postback the dynamic control is gone unless you add it in the
pre-init.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top