CodeSnip: Find Control in Nested Master Pages
page 3 of 4
by Abdulla Hussein AbdelHaq
Feedback
Average Rating: 
Views (Total / Last 10 Days): 14180/ 240

Solution

First of all, we should search about the content place holder of the outer master page, and then search about the content place holder of the inner master page. Finally, we will search deeply inside the two content place holders about our label control.

Listing 4 is the code that you need to write.

Listing 4: Find control inside nested master pages

' Outer Master Page
Dim Outer_CP As ContentPlaceHolder
Outer_CP = TryCast(Me.Master.Master.FindControl("ContentPlaceHolder1"), _
ContentPlaceHolder)
 
' Inner Master Page
Dim Inner_CP As ContentPlaceHolder
Inner_CP = TryCast(Outer_CP.FindControl("ContentPlaceHolder2"), _
ContentPlaceHolder)
Dim lbl As Label = TryCast(Inner_CP.FindControl("Label1"), Label)
 
lbl.Text = "Text was changed inside nested master page!"

View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 5 and 5 and type the answer here:

User Comments

Title: developer   
Name: netslaves
Date: 3/9/2010 8:27:32 AM
Comment:
thanks
Title: Great logic!   
Name: d-cpt
Date: 8/17/2009 10:45:31 AM
Comment:
Excellent article.
Thanks a lot.
Title: Less Code   
Name: Lannie Lawton
Date: 7/18/2009 3:26:25 PM
Comment:
Dim lbl As label = Me.Master.Master.FindControl("ContentPlaceHolder1$ContentPlaceHolder1$Label1")

Would work too, at least in VS 2008.
Title: good explaination   
Name: soma sekhar
Date: 6/23/2009 2:52:21 AM
Comment:
this is good example to get master page controls
Title: Great   
Name: Abidali
Date: 3/24/2009 8:21:40 AM
Comment:
nice article
Help me lot

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2010 ASPAlliance.com  |  Page Processed at 3/20/2010 5:01:16 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search