Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to unload the web user control

Reply
Thread Tools

how to unload the web user control

 
 
buran
Guest
Posts: n/a
 
      04-24-2004
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


 
Reply With Quote
 
 
 
 
Ashish M Bhonkiya
Guest
Posts: n/a
 
      04-25-2004
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.as cx"));

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


HTH
Regards
Ashish M Bhonkiya


"buran" <> wrote in message
news:...
> 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
>
>



 
Reply With Quote
 
 
 
 
buran
Guest
Posts: n/a
 
      04-26-2004
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" <> wrote in message
news:...
> 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.as cx"));
>
> // Code for Removing the UserControl
> Control myControl = PlaceHolder1.Controls[0];
> PlaceHolder1.Controls.Remove(myControl);
>
>
> HTH
> Regards
> Ashish M Bhonkiya
>
>
> "buran" <> wrote in message
> news:...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Ashish M Bhonkiya
Guest
Posts: n/a
 
      04-27-2004
Hi Buran,

You can check it in the page_load event of the usercontrol, checking value
for Page.IsPostBack.

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

/// <summary>

/// Summary description for postbackUC.

/// </summary>

public class postbackUC : System.Web.UI.UserControl

{

private void Page_Load(object sender, System.EventArgs e)

{

if (Page.IsPostBack)

{

Response.Write("This is a PostBack... haahaah");

}

else

{

Response.Write("This is not a PostBack...");

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}


HTH
Regards
Ashish M Bhonkiya


"buran" <> wrote in message
news:...
> 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" <> wrote in message
> news:...
> > 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.as cx"));
> >
> > // Code for Removing the UserControl
> > Control myControl = PlaceHolder1.Controls[0];
> > PlaceHolder1.Controls.Remove(myControl);
> >
> >
> > HTH
> > Regards
> > Ashish M Bhonkiya
> >
> >
> > "buran" <> wrote in message
> > news:...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web User Control with GridView can derive new Web User Control? ABC ASP .Net 1 10-04-2005 12:29 PM
Web User Control with GridView can derive new Web User Control? ABC ASP .Net Web Controls 0 10-03-2005 10:23 AM
Web User Control with GridView can derive new Web User Control? ABC ASP .Net 0 10-03-2005 10:23 AM
Dynamic control array loading, can't unload control/replace with o =?Utf-8?B?Y2luZHk=?= ASP .Net 2 06-08-2005 03:54 AM
UnLoad not been called in Web User Control Dinesh Reddy N Y ASP .Net Web Controls 0 04-13-2004 04:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57