473,396 Members | 1,924 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,396 software developers and data experts.

Dynamic control array loading, can't unload control/replace with o

I have a web form with 3 links, depending on which link is clicked a user
control loads, page1.ascx,page2.ascx,page3.ascx

page1.ascx does a search, uses 3 asp:dropdownlists with viewstate true and
auto post back. It loads by default first time.

User clicks on link 2, page2.ascx loads after page1.ascx I need the loaded
control to go away when a different one is clicked, I have seen similar
stuff on threads but I can't understand a clear answer on what syntax and
where in the order?

I do not understand the syntax for controls.remove the sample says
control.remove where control.name =
and there is no controls.name in c sharp syntax for this? Also I am using
control array see below

private void OnPageButtonClick(object sender, System.EventArgs e)
{
LinkButton pageButton = (LinkButton)sender;
string pageNumber = pageButton.ID.Substring("_pageButton".Length);
ActiveTab = pageNumber;
SelectPage(pageNumber);
}
public void SelectPage(string pageNumber)
{
Control page = LoadControl(String.Format("Page{0}.ascx", pageNumber));
_content.Controls.Add(page);
LinkButton pageButton = FindControl(String.Format("_pageButton{0}",
pageNumber)) as LinkButton;
if (pageButton != null)
{
pageButton.BackColor = Color.Gold;
pageButton.CssClass = "tabon";
}
LastActiveControl = page.ID.ToString();
}
--
cindy mello
Nov 19 '05 #1
2 2161
I'm assuming your "_content" is a container Control. If so, try
_content.Controls.Clear(); before you add the next control.

"cindy" wrote:
I have a web form with 3 links, depending on which link is clicked a user
control loads, page1.ascx,page2.ascx,page3.ascx

page1.ascx does a search, uses 3 asp:dropdownlists with viewstate true and
auto post back. It loads by default first time.

User clicks on link 2, page2.ascx loads after page1.ascx I need the loaded
control to go away when a different one is clicked, I have seen similar
stuff on threads but I can't understand a clear answer on what syntax and
where in the order?

I do not understand the syntax for controls.remove the sample says
control.remove where control.name =
and there is no controls.name in c sharp syntax for this? Also I am using
control array see below

private void OnPageButtonClick(object sender, System.EventArgs e)
{
LinkButton pageButton = (LinkButton)sender;
string pageNumber = pageButton.ID.Substring("_pageButton".Length);
ActiveTab = pageNumber;
SelectPage(pageNumber);
}
public void SelectPage(string pageNumber)
{
Control page = LoadControl(String.Format("Page{0}.ascx", pageNumber));
_content.Controls.Add(page);
LinkButton pageButton = FindControl(String.Format("_pageButton{0}",
pageNumber)) as LinkButton;
if (pageButton != null)
{
pageButton.BackColor = Color.Gold;
pageButton.CssClass = "tabon";
}
LastActiveControl = page.ID.ToString();
}
--
cindy mello

Nov 19 '05 #2
Hi Cindy,

I've also noticed your another previous post in the

" 03 dropdownlist selectedindexchanged not firing in usercontrol on"

microsoft.public.dotnet.framework.aspnet.webcontro ls

newsgroup, I've also attached a demo package there. Have you had a chance
to test it? Also, as for the unloading usercontrol, I think we should
follow the following two steps according to my description in the former
thread:

1. In the first postback of the 3rd link(which will remove the first 2
usercontrols), we can use Container.Controls.Clear to clear the control
collection, we can also use Controls.Remove to remove the control instance
from it's parent collection( use FindControl to get the reference first)

2. Also, set the flag in ViewState accordingly since the sequential
postback will create dynamic controls denpending on these values.

If have anything unclear or have any problems accessing the demo pages I
attached there, please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3

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

Similar topics

3
by: Michael Sgier | last post by:
Hello I want to replace a windows bitmap load function through an equivalent SDL function. I should extract the img height etc. and assign it to the terrainTex array. I've also three beginner...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
3
by: buran | last post by:
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"...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
13
by: PW | last post by:
Hi, This is bizarre. I've check and rechecked the spelling, cut and paste the name of the form (when trying to rename the form) and the control yet I still get a parameter prompt when the form...
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...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
2
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a web app that when I click a menu, I load a control. On one of these controls, I have a button that when clicked, I need to unload the control to unload itself and load a different control...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.