how to unload the web user control

Discussion in 'ASP .Net' started by buran, Apr 24, 2004.

  1. buran

    buran Guest

    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
    buran, Apr 24, 2004
    #1
    1. Advertising

  2. 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" <> 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
    >
    >
    Ashish M Bhonkiya, Apr 25, 2004
    #2
    1. Advertising

  3. buran

    buran Guest

    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.ascx"));
    >
    > // 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
    > >
    > >

    >
    >
    buran, Apr 26, 2004
    #3
  4. 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.ascx"));
    > >
    > > // 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
    > > >
    > > >

    > >
    > >

    >
    >
    Ashish M Bhonkiya, Apr 27, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y2luZHk=?=
    Replies:
    2
    Views:
    2,586
    Steven Cheng[MSFT]
    Jun 8, 2005
  2. ABC
    Replies:
    1
    Views:
    2,634
    Larry
    Oct 4, 2005
  3. ABC
    Replies:
    0
    Views:
    477
  4. Dinesh Reddy N Y

    UnLoad not been called in Web User Control

    Dinesh Reddy N Y, Apr 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    141
    Dinesh Reddy N Y
    Apr 13, 2004
  5. ABC
    Replies:
    0
    Views:
    196
Loading...

Share This Page