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

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
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.
 
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
 
Back
Top