How to access individual controls from a form containing the web user control containing those controls

 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control.

Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)

 

1    if(!Page.IsPostBack)

2    {

3     edAddNewZipCodes userControl = (edAddNewZipCodes)Page.LoadControl("edAddNewZipCodes.ascx");

4     PlaceHolder1.Controls.Add(userControl);

5    }

0
AppDevForMe
8/29/2007 4:18:53 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
1700 Views

Similar Articles

[PageSpeed] 57

After you add the control to your placeholder try the below code

Label label = (Label)userControl.FindControl("Label3");

label.Visible = false;

HC


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
8/29/2007 4:32:39 PM

Unless you have a public property or method exposed by your user control which will set the visibility of this Label control, then you're out of luck. Your best bet is to add some type of Visibility property to your user control which will set the visibility of your Label. Then, you simply need to access this property from your user control reference and set it accordingly.

if (!Page.IsPostBack)
{
	edAddNewZipCodes userControl = (edAddNewZipCodes)Page.LoadControl("edAddNewZipCodes.ascx");
	userControl.Label3Visible = false;
	PlaceHolder1.Controls.Add(userControl);
}

USER CONTROL 

public bool Label3Visible
{
	get { return Label3.Visible; }
	set { Label3.Visible = value; }
}

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
8/29/2007 4:33:38 PM
Reply:

Similar Artilces:

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Persisting data in a web user control, which contains a list of other web user controls.
 Hi All, I have a control I've created, which can have a number of child controls - also user controls - stored as an ArrayList, which can be added wither a design time or programmatically.My problem is when I add to the list programmatically, it doesn't persist them. So if I add 3 child controls in step 1 of a wizard, with the aim that those three will be visible inside the parent in step 3, what happens is that the parent has no child controls and the item count is 0.Can anyone help? Thanks in advance.Code:Parent Control Markup: <%@ Control Language="C#" Auto...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Importing Individual Web Forms and User Controls from a Web Site
Is there a best practice for importing individual web forms and user  controls from a web site to a web application project (i.e., to ensure the .designer file is generated and all that)? On the new version of an existing web site, we're moving the WAP, but we're changing the project enough that I don't want to just upgrade the whole thing--I just want to import select forms and controls. So far, the best thought I've got is to do a fake upgrade and copy over files from that, but that's a bit heavy for my needs, so if there's an easier or better way to just grab the ones I want, pleas...

Web Server Control Containing another Web Server Control?
I'm building a web server control that needs to include functionality from 3rd party web server control, ASPNetMenu. My web server control needs to render ASPNetMenu at runtime to create a menu. I'd like to do this so that my control's parent ASPX page does not need to register ASPNetMenu or make any configuration changes as this should be done through my web server control. Does anybody have any suggestions on how to do this? Mike - Cache entire web sites at the client and server and keep cache current. Cache just got easier! There are two articles that you would want to be int...

User Control Within UserControl
If I have a user control A and then inside it a user control B embedded/referenced within it.  User Control A has a panel defined (cpeNewUser) that I want to manipulate from the code behind of User Control B based on some event that happens.So putting this in my code behind of User Control B won't work as it has no idea of cpeNewUser:cpeNewUser.Collapsed = true;So is it because only at runtime they are married up and because of this you cannot access each other's objects at compile time?  How would I get this to work becuase I'm using all user controls inside a AJAX Too...

Datagrid in User Control on Web Form contained in iFrame
My current web project (VB) is requiring me to have a User Control containing a searchable DataGrid of numerous items. I have it to where the DataGrid is scrollable and the header sits still. I have also added mouseover and mouseout events to show highlighted rows while the mouse is over them. (< a href="http://www.dotnetbips.com/displayarticle.aspx?id=205" >http://www.dotnetbips.com/displayarticle.aspx?id=205</ a >) Now, I have also included an event to select the item when it is clicked on anywhere on the row. I have all of this contained on another web form wit...

Web resources about - How to access individual controls from a form containing the web user control containing those controls - asp.net.web-forms

Gymnastics at the 2012 Summer Olympics – Women's artistic individual all-around - Wikipedia, the free ...
... go through to the Team final, where three team members compete on each apparatus. Teams are ranked on their total score. The best 24 individual ...

"It is a near-religious teaching among many people today that if you are against sexual assault, then ...
... assaulted. That possibility makes me feel both that I am unsafe and that my school is a sexually hostile environment. Under this logic, individuals ...

AG Lynch Explains Obama’s Gun-Control: Gov’t Looking For ‘Individuals Who Seek To Avoid Registering’
AG Lynch Explains Obama's Gun-Control: Gov't Looking For 'Individuals Who Seek To Avoid Registering'

Tax Credits For Low-Carbon Individuals & Businesses
... electricity sources? How can they partner to get more people in transit and on bikes? How can they [&hellip Tax Credits For Low-Carbon Individuals ...

Trump's doctor: Trump 'will be healthiest individual ever elected' president
CNN Trump's doctor: Trump 'will be healthiest individual ever elected' president CNN Washington (CNN) Donald Trump on Monday released a letter ...

Curry on individual awards: 'Beauty of basketball is it's a team sport'
... Search form Search 42° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Curry on individual ...

49 Out Of 50 States Will See Individual Health Care Premiums Go Up In 2016
49 Out Of 50 States Will See Individual Health Care Premiums Go Up In 2016

Trump's personal doctor: Trump would be 'the healthiest individual ever elected to the presidency'
Good news: Donald Trump's doctor says Donald Trump would be the "healthiest individual ever elected to the presidency." He's just that super-healthy ...

DARPA wants help hunting for individual photons
America's mad science division wants the ability to see the building blocks of light, but needs the scientific community's help to do so. The ...

Chris Brown Responds to Assault Allegations, Slams 'Crazy Individuals Who Keep Lying on My Name'
The 26-year-old rapper took to Instagram on Saturday to address allegations that he struck a woman in a Las Vegas hotel.

Resources last updated: 1/19/2016 3:59:52 AM