A standardized method to access to controls that are within a Templated Control.

Hello,

As all of us we know, lots of controls are of the type of "templated controls".

This controls can hold, in any of their templated sets other controls.

The problem arise when we try to access to the aforementioned controls in the code-behind/beside (I don't know yet how to name this model) file.

Could be, in anyway, implemented a standardized way to access to those controls?

Apologize my ignorance in this topic.

Greetings.


VB .Net Coder - Apologize my C# nescience
Best Regards.
0
ByReckon
4/25/2005 9:28:58 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

6 Replies
775 Views

Similar Articles

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

Hello.

What are you trying to do? you can always use FindControl as your last resort, but maybe there's an easier way of doing what you want. maybe if you coiuld give more details on this we could give you further info.


--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
0
Luis
4/25/2005 2:13:20 PM

Hello Luis,

I'm getting mad because I can't find controls when they are contained within a Templated Control. It doesn't matter in which event I try to find them.

For example, take a look at this code using a LoginView Control:

[...]

<asp:LoginView id="logView" runat="server">

<AnonymousTemplate>

<asp:Label id="lblAnoText" runat="server" />

</AnonymousTemplate>

</asp:LoginView>

[...]

Now, I want to access to the "lblAnoText" since my code-behind/beside file. I have used the FindControl method in almost every event of the Page class, as well as with the events of the LoginView Control. In either case, no luck.

I'm sure I'm doing something wrong, but I can't see where. I'm blind right now with this issue, and I'm sure the solution is very close.

Thanks in advance.


VB .Net Coder - Apologize my C# nescience
Best Regards.
0
ByReckon
4/25/2005 2:44:20 PM

Hello, I'll show the snippet of code I'm using to Find the Label within the <AnonymousTemplate>.

First, I'm using the Pre_Render event. The reason of using this stage is that final changes to the contents of the page must be done here.

[...]

'Pre_Render Event

If Me.FindControl("logView") IsNot Nothing Then
      If Me.logView.FindControl("lblAnoText") IsNot Nothing Then
               Response.Write("Label control has been found")
      Else
               Response.Write("LoginView has been found, but not luck with the label")
      End If
End If 

[...]

I'm totally blind.

I can't find that control contained inside the <asp:LoginView>. Maybe I'm wrong in the event choosed, or in the way I try to find the control. I don't know.

Any help would be very appreciated.


VB .Net Coder - Apologize my C# nescience
Best Regards.
0
ByReckon
4/25/2005 7:33:24 PM

Hello again,

Well, this issue is a bit weird.

The <asp:LoginView> control has a property Controls which returns a ControlCollection object that contains the child controls of the LoginView control.

Using my <asp:LoginView> control exposed in one of my previous posts, the following code returns 0.

[...]
If Me.FindControl("logView") IsNot Nothing Then

   Response.Output.Write("Child controls {0}", Logview.Controls.Count.ToString)

End If
[...]

The code seems to be-error free, but the results are not the expected.

Any idea?


VB .Net Coder - Apologize my C# nescience
Best Regards.
0
ByReckon
4/25/2005 8:42:43 PM

Hello.

That looks correct. However, remember that the anonymous template will only be instantiated if you're accessing the site as an anonymous user. If you're a logged in user, I think that the anonymous template will not be instantiated and you'll gett null when trying to use the FindControl method.


--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
0
Luis
4/25/2005 8:44:11 PM

Hello Luis,

you are completly correct.

I've checked if I'm authenticated by using:

HttpContext.Current.User.Identity.IsAuthenticated

Which returns True.

But why I'm authenticated? Because I didn't take into account that the default Authentication mode is... Windows. I did not change the <authentication mode> of my web.config. That's the reason why LoginView.Controls returns 0, even though in my <AnonymousTemplate> there is one. I'm already logged under my OS. And this template is never showed to an authenticated user.

Once changed in my web.config file to <authentication mode="None">, all seems to work correct.

Too much reading about MemberShip, DataSources and so on with new features. I have to review all about ASP.NET 1.x.

Thanks for the advice. I was totally blind with this.

Thanks a lot.


VB .Net Coder - Apologize my C# nescience
Best Regards.
0
ByReckon
4/25/2005 9:11:08 PM
Reply:

Similar Artilces:

Access a controle within a controle
HelloI have a Datalist binded with a ObjectDataSource, wich then loads troughout a Class that uses storedprocedures.Now I want to customize a part of the DataList, I dropped a Label into the Datalist. Is there any simple way of accessing this label in the partial class of the aspx file? You'd normally call the parent control's FindControl() method. So, if your DataList had an ID of "DataList1" and your Label had an ID of "Label1" you do something like:Label lbl = (Label)DataList1.FindControl("Label1");lbl.Text = ...

Accessing controls within controls...
I am trying to write a sub that clears all textboxes on my page when it is called. I started with: Public Sub ClearForm()      Dim ctl As Control      For Each ctl In Page.Controls(1).Controls            Response.Write(ctl.ID)            If TypeOf ctl Is TextBox Then               CType(ctl, TextBox).Text = ""           ...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

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

Why is my ATLAS TEMPLATED USER CONTROL getting all instances of this controls methods called? I only want it called for the instance that I click the button from...
I have created a templated user control and it uses ATLAS. So...once the control loads, it then makes an ajax call to populate itself. "server" UpdateMode="Conditional" ID="UpdatePanel1" ChildrenAsTriggers="False" > "TNews1" runat="server"> BNNews(<%# Container.Row["TotalItems"].ToString()%>) <%# Container.Row["NewsID"] %> - "BNP35.aspx?newsId=<%# Container.Row["NewsID"]%>&promoId=<%# TN...

How to access controls within LoginView-Control?
.... <asp:LoginView ID="LoginView1" Runat="server"> <LoggedInTemplate> <font color="#ffffff">Logged in as:&nbsp; <asp:LoginName ID="LoginName1" Runat="server" ForeColor="White" /> </font> </LoggedInTemplate> ...

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

Access controls within LoginView-Control
Hello, I have a problem accessing controls within the LoggedInTemplate or the AnonymousTemplate of a LoginView-Control. For example, I have a asp:Label in the LoggedInTemplate with ID=lblWelcomMessage. In my page_load-method, I have: ((Label)LoginView1.FindControl("lblWelcomMessage")).Text = "some text"; This results in a System.NullReferenceException: Object reference not set to an instance of an object error. The LoginView1 is on my Master Page. The rendered HTML looks like this: <td style="width: 550px; height: 14px;" class="white_text_sma...

howto access controls within template (like formview.insertitemtemplate ...) without FindControl method ?
Hello forum, How can i access webcontrol in code-behind within a template WITHOUT using FindControl ? Thank you ;).NET dev/archi There's not any way that I'm aware of...  If the container's parent doesn't expose it as a property, you'll have to use FindControl eventually....

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

NullReferenceException when accessing standard control from User Control
Hi All, I've scoured the web for an answer to this to no avail. I've developed a dual list control that has a few standard controls on it (2 list boxes, some buttons etc). I've defined the following property on said user control:     [Description("The field in the data source which provides the item text."),     Category("Data"),     DefaultValue(DATA_TEXT_FIELD_DEFAULT)]    public string DataTextField    {       get { return m_dataTextField; }       set       {       &nbs...

Access controls in Wizard control header template.
Is this possible?Web dev - spending forever achieving nothing. hi, suppose the control in the header template is a DDL with Id DropDownList1 access it this way DropDownList dp = (DropDownList)Wizard1.FindControl("headerContainer$DropDownList1");        Response.Write(dp.SelectedValue); hope it helpsJessica CaoSincerely,Microsoft Online Community Support“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community ...

Accessing Web Controls within a User Control
Hi, I've built a page which contains a user control. The contents of this user control is a dynamically-built series of radiobuttonlists. What I need to be able to do is access these radiobuttonlists from the code behind the outer page, the one containing the user control. However, it seems as though I cannot do this. Looping through control.controls I can see a placeholder control within my user control, but not the dynamically generated radiobuttonlists beneath it. As far as I'm aware you can usually access dyanamically generalted controls by using control.controls, but this seems di...

web control help, how to get to the method in the control
I have created an upload web control and I am trying to use it on an aspx page. I had a load button in the control however I was asked to remove it from the control and add the button to the aspx page. I created a method in the control that will load the images but I am not sure how to get to this method from the aspx page ? can someone help me to understand what I need to do..  Thank you so much for all the help :)Gina  UserControlInstance.MethodName();...

Web resources about - A standardized method to access to controls that are within a Templated Control. - asp.net.getting-started

Standardized test - Wikipedia, the free encyclopedia
Any test in which the same test is given in the same manner to all test takers is a standardised test. Standardised tests need not be high-stakes ...

Standardized Testing is not Teaching - YouTube
This video provides an evidence-based overview of the some issues associated with standardized testing.

China to implement standardized training for medical graduates in 2015
China to implement standardized training for medical graduates in 2015 People's Daily Online Global TimesChinadaily.com.cn Ecns.cn Show ChinaChina ...

iOS 7 to include support for standardized, MFi hardware game controllers, new turn-based game modes ...
In what seems to be an announcement lost within the buzz of iOS 7 and OS X Mavericks (amongst other WWDC news), Apple will finally open up the ...

Location Shooting Process Would Be Standardized Under Plan
Cities, counties urged to adopt California Film Commission guidelines under plan endorsed by L.A. Economic Development Corp., FilmL.A.

The New York Times Brings Standardized Rich-Media Ads to Its iPad App
... Idea Lab, a 10-person outfit inside the company that partly applies editorial innovations to new online ad products, is introducing new standardized ...

New standardized test scores show long-standing gap between Anchorage’s rich, poor schools - Alaska Dispatch ...
... achievement gap between schools in rich and poor neighborhoods that has long plagued Anchorage as well as the rest of the country. New standardized ...

Chicago teachers boycott standardized tests
Chicago citizens propose to #ICEtheISAT About 40 teachers at Chicago Public Schools boycotted a state-issued standardized test Tuesday by refusing ...

Florida Republican says standardized tests make you gay
... come up with. A Florida Republican lawmaker, Charles Van Zant, as part of his larger opposition to “Common Core,” has determined that standardized ...

Learning: Standardized tests go digital, raise questions
... Kimberly Varela won't miss the white-knuckled grasp of a No. 2 pencil or filling countless columns of test-booklet bubbles when standardized ...

Resources last updated: 1/12/2016 10:59:17 PM