how to unload the web user control

B

buran

Dear ASP.NET Programmers,

I am loading a web user control ("taclient.ascx") into a placeholder (ID:
phFA). The web user control contains a cancel button (ID: btnCancel). I
would like to "unload" the web user control when the user clicks on the
cancel button. How can I accomplish this? Thanks in advance.

dim myControl as Control
myControl = LoadControl("taclient.ascx")
phFA.Controls.Clear()
phFA.Controls.Add(myControl)

Buran
 
A

Ashish M Bhonkiya

Hi buran,

When ever you are loading the usercontrol dynalically, you need to take care
of loading the usercontrol again on the postback event, so if the user has
clicked the cancel button then in that case dont load the usercontrol that
is one of the ways.

other possible way is

// Code for Adding the User Control
PlaceHolder1.Controls.Add(LoadControl("taclient.ascx"));

// Code for Removing the UserControl
Control myControl = PlaceHolder1.Controls[0];
PlaceHolder1.Controls.Remove(myControl);


HTH
Regards
Ashish M Bhonkiya
 
B

buran

Thanks for your help. I have another question. How can I detect the postback
IN my user control? I am loading the user control every time the parent page
is posted back, but how can I detect the post back in the user control?

Buran

Ashish M Bhonkiya said:
Hi buran,

When ever you are loading the usercontrol dynalically, you need to take care
of loading the usercontrol again on the postback event, so if the user has
clicked the cancel button then in that case dont load the usercontrol that
is one of the ways.

other possible way is

// Code for Adding the User Control
PlaceHolder1.Controls.Add(LoadControl("taclient.ascx"));

// Code for Removing the UserControl
Control myControl = PlaceHolder1.Controls[0];
PlaceHolder1.Controls.Remove(myControl);


HTH
Regards
Ashish M Bhonkiya


buran said:
Dear ASP.NET Programmers,

I am loading a web user control ("taclient.ascx") into a placeholder (ID:
phFA). The web user control contains a cancel button (ID: btnCancel). I
would like to "unload" the web user control when the user clicks on the
cancel button. How can I accomplish this? Thanks in advance.

dim myControl as Control
myControl = LoadControl("taclient.ascx")
phFA.Controls.Clear()
phFA.Controls.Add(myControl)

Buran
 

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

Top