How to access a child control in a templated control?

I am not sure how to access a child control that I addes to a templated control.

For example:

I drag a Login Control (ID: "Login1") into page in VisualStudio web developer, I can click on it and from the upper right of that control now in my desinger I can choose "convert to template". 

Now I can drop in my own control to be added to the Login Control.  Let say I drag over a DropDownList control (ID: "DropDownList1") and place it at the bottom within the Login Control.

At run time I might expect to access the my DropDownList control with something like:

protected void Page_Load(object sender, EventArgs e)


   // Trying to access a child control in a templated control.  This does not work.

    this.Login1.DropDownList1.SelectedIndex = 1;


This does not work.  I assume it is because a child control dropped into a template in the visual studio page designer doesn't mean it is automatically exposed as property.

What is the proper way to access that child control at run time for this example?

Thanks for any help!


1/23/2006 1:58:53 AM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 44
Get it on Google Play
Get it on Apple App Store

Try this instead:

    protected void Page_Load(object sender, EventArgs e)
        DropDownList dl = Login1.FindControl("DropDownList1") as DropDownList;
        dl.SelectedIndex = 1;

1/23/2006 2:40:22 AM

Similar Artilces:

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&nb...

Accessing Child Controls of a Template Server Control
I've created a templated control that has a property called ContentTemplate which is of type ITemplate.  The control works great with the exception of I now have to interact with the child controls via the FindControl method. Markup: <test:MyControl ID="testControl" runat="server"> <ContentTemplate> <asp:Label ID="testLabel" runat="server" /> </ContentTemplate> </test:MyControl>    In order to interact with the child label, testLabel, I now need to do something like this:Dim lbl As La...

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...

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: 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...

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 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 ...

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...

Passing values from a parent web control to child web control
I have a parent control which called CONTROL1 and a child control witch called CONTROL2 I would link to pass a value from the parent control to the child control. In the parent control(CONTROL1) I have the following Event Handler . private void btn_Handler(object sender, EventArgs e) { …      if (Page.IsPostBack) {              // Send the officer names to the child controls.             if(m_nameList.SelectedItem.Text != "")     ...

Web control in web control
Hi,There are two simple web user controls A and B, where B contains A. They just display the bunch of text boxes, so I do not need them even in tool pane. They sit in the same project next to web form.I noticed that web user control put on ASPX page does not appear in code behind, but if I create it with protected keyword and name being exactly the same as id it works fine. I can access such a web control from code behind and see the value assigned in IE. The problem is that the same routine does work for my A web control in B. When I assign the value IE, I keep getting null reference. ...

Serverside Template Control
I've created a template control what I am running into difficults is during the Page_Load event on my web page I cannot access the child controls in the two possible templates. What I would like to be able to do is set the value or make some changes to the control at runtime but I have not been successful in gaining code access to the control, for example the TEXTBOX1 control in the EditTemplate template.     Does anyone know a good way to preform this task, let alone if I am even using the correct event Example of HTML Render  <aspSample:TextLabe...

controlling an object in a web control from the page the web control is placed in
I have created a web control in that has an image button and an image. when it loads the image button is visible and the image is not. I want to be able from the page which "includes" the web control to set the image button to invisible and the image to visible. When I tried this, the main page didn't recognise the image button or the image (both < asp: objects). help would be gratefully appreciated. oh yeah, it's inline code so any code behind stuff will just confuse me ;) Some code please.-- Justin Lovell...

accessing a control on a different web controls
I have 2 web controls on one aspx page.  I want to set the label1.text property on control1 from a button click event on control2.  Is there any to do that?     Thanks Hi,the strategy is to let the Page take care of this flow. To do this, first expose the Label's text with a property declared in Control1, for example<% Control Language="C#" %><script runat="server">public string Text {    get { return myLabel.Text; }    set { myLabel.Text = value; }}</script><asp:Label id="myLabel" runat="server"></asp:Label>...

Accessing form controls from a user control
What's up all,I have a user information form in a user control(standard input fields). When I used use VS 2003 I could set the declared Web Controls to "public" so I could access them from the page referencing the user control..But with VS 2005 I can't seem to find a way to access the declarations of the individual Web Controls to make them public.Would it be a better idea to make a property for each control, within the user control and make those public to retrieve the data? Thanks!Gary It's a good OOP practice to create a public property within the UserControl to expose access...

Accessing Child Controls in Accordian Control
 I have an html button inside an accordion control. Does anyone know how I can access it so I can set the visible property to false? Dim b as Button = CType(yourAccordian.FindControl("yourButton"),Button)b.Visible = false  Thanks for the quick reply! Would it be at all possible if you could convert that to C#?  Thanks  Bookmark this one: {     Button b = (Button)yourAccordian.FindControl("yourButton");     b.Visible = false; }  Seems I might ne...

Web resources about - How to access a child control in a templated control? -

Facebook will soon start showing templated News Feeds to users without the app
Earlier this week, we wrote that our #1 request for improving News Feed functionality was the need to publish application stories to friends ...

François Beaufort - Google+ - Rich templated notifications are now available through the…
Rich templated notifications are now available through the new Notification Center in the last Windows chromium build available at…

“Scroll Kit” Tool For De-Templated Design Goes Live, Adds New Features
Synchronized perfectly with the start of the annual SXSW conference in Austin, Cody Bown and Kate Ray have announced improvements to their design ...

RNA-Catalyzed RNA Polymerization: Accurate and General RNA-Templated Primer Extension
The RNA world hypothesis regarding the early evolution of life relies on the premise that some RNA sequences can catalyze RNA replication. In ...

Wikipedia:Wikipedia Signpost/Newsroom/Suggestions - Wikipedia, the free encyclopedia
This page is for suggesting news to be covered in the next Signpost . For general discussion, comments or questions regarding The Signpost , ...

Wikipedia:Sockpuppet investigations - Wikipedia, the free encyclopedia
WP:RFCU redirects here. You may be looking for Wikipedia:Requests for comment/User conduct ( WP:RFC/U ), CheckUser policy ( Wikipedia:CheckUser ...

Recent changes - Wikitravel
Help Wikitravel grow by contributing to an article. Learn how . Recent changes From Wikitravel Jump to: navigation , search Track the most recent ...

Symbiosis Episode 46 – Blue Daisy
Blue Daisy exclusive mix & interview for Symbiosis. Blue Daisy aka Kwesi Darko hails from London and is signed to Black Acre. Not your typical ...

Government House NT - Patronages footer menu
The Office of the Administrator uses a selection of templated forms to assist organisations that are hosting the Administrator of the Northern ...

Why Zelda Still Rules the Action RPG
The Legend of Zelda games may not be perfect, but they still define the genre.

Resources last updated: 1/22/2016 9:42:38 PM