473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to unload the web user control

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
Nov 18 '05 #1
3 8511
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" <bu***@buran.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #2
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" <bh******@hotmail.com.nospam> wrote in message
news:es**************@TK2MSFTNGP09.phx.gbl...
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" <bu***@buran.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #3
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" <bu***@buran.com> wrote in message
news:er**************@TK2MSFTNGP11.phx.gbl...
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" <bh******@hotmail.com.nospam> wrote in message
news:es**************@TK2MSFTNGP09.phx.gbl...
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" <bu***@buran.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
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



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
6
by: Ronald S. Cook | last post by:
We have a Windows app that has one main form (a shell, sort of). We then load user controls into a panel on the form depending on what the user has selected. Our current code to unload the...
2
by: Ronald S. Cook | last post by:
I have a Windows app with a split container (SplitContainer1) that contains two panels (Panel1, Panel2). I would like to load a user control (utcMyTest) into Panel2 on form load. Can someone...
0
by: Ethan Strauss | last post by:
Hi, I have a page which dynamically creates a bunch of instances of a single user control and loads them into the cells of a table. Users will then be able to alter the settings in each user...
2
by: adiel_g | last post by:
I added a user control to a webform in Asp.net 2.0. I am also adding several other user controls to this webform. Now I am trying to find a way to stop the user controls from loading up when I...
2
by: HammRadio | last post by:
I am exploring converting my web app (current Framework 1.1) to Framework 2.0. Everything went smoothly save for one item. To reduce the trips to the database, when loading user controls (like a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.