No, you don't need the same number of Content Templates in your MasterPages.
That advice is just plain wrong. When compiled the contents of the Content
Template are extracted and integrated into the control tree as required. The
Content Template itself is discarded. You can verify this by enabling trace
in a content page and reading the control tree. Where is the Content
Template? Poof! Gone as it is only used in the designer to isolate
declarations for the compiler.
When you use trace in this way you will also see the entire template
hierarchy where your control is located. You will also likely observe how
some template sections have been renamed. One way or the other we must use
the entire template hierarchy to reference a control nested in templates. An
example follows...
// Step 1 use code to determine which MasterPage is loaded
// Step 2 use trace to read the control tree to located the control you want
to reference
// Step 3 use the FindControl method to reference the control using the
control tree hierarchy grammar
// Note: changing the source can affect the control tree hierarchy which may
require you to change your FindControl control tree grammar.
// example control tree hierarchy
ctl00$InnerPanelContent$CreateUserWizard$__CustomN av2$CreateUserButton
// replicate control tree hierarchy grammar to cast the referenced control
to its type
Button createUserButton =
(Button)Page.Master.FindControl("InnerPanelContent ").FindControl("CreateUserWizard").FindControl("__ CustomNav2").FindControl("CreateUserButton");
// use the referenced control
createUserButton.Text == "Button Text";
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL
http://www.metromilwaukee.com/clintongallagher/
"Islamegy®" <Is******@Private.4me> wrote in message
news:Oy*************@TK2MSFTNGP05.phx.gbl...
But this label is added in the child page not in the masterpage... When i
search in the way u mention i don't find the label!!!
any ideas??
"Bruno Alexandre" <br*********@gmail.com> wrote in message
news:uk**************@TK2MSFTNGP03.phx.gbl... imagine that you have a Label called myLabel and you want to set a new
text
cType( MasterPage.FindControl("myLabel"), Label).Text = "this is the new
text"
MasterPage.FindControl("myLabel") is your object from masterPage, then
you cast it to a label so you can acess all the properties of a Label
Object, than you specify the property you want to acess, in this case
Text, and you bind the value you want.
you can do the same in two lines of code like:
Dim myNewLabel as Label = cType( MasterPage.FindContrl("myLabel"),
Label )
myNewLabel.Text = "this is the new text"
--
Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Islamegy®" <Is******@Private.4me> escreveu na mensagem
news:eU**************@TK2MSFTNGP04.phx.gbl... Is this a solution for the first issue, I must hv the same number and
IDs for contentpanels in all master pages!!!
ok.. What about find controls in runtime when use masterpage??
"Bruno Alexandre" <br*********@gmail.com> wrote in message
news:ud**************@TK2MSFTNGP02.phx.gbl...
I think all masters have to had the same number of contentHolders...
try that (in the page you have just one, add the 2nd to the bottom of
the page for example)
do not forget that both masters have to have the same id's for
contentHolder
this is only vecause you are using it dynamically, normal use don't
need this issue.
--
Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Islamegy®" <Is******@Private.4me> escreveu na mensagem
news:%2****************@TK2MSFTNGP03.phx.gbl...
> In my project i have two master page which i change dynamic in
> runtime.. The first one with 1 ContentPanel "onepanel.master", the
> second with 2 contentPanel"twopanel.master"..
>
> but when i switch between them it don't work, if the default
> masterpage is "onepanel.master" and try to change it in runtime,
> ContentPanel2 which is exist in the loaded masterpage throw
> exception..
> the same happen if the default is "twopanel.master" and switch it
> throught exception when parsing html..
> Is there anyway to work around this without have 2 pages??
>
> Second Question.. I can't find controls using FindControl When use
> masterpage, i notice that my page only have one control which is the
> masterpage,
> if i search deeper in Controls[0].FindControl i find 2 literal and 2
> HtmlHead(!!!) .
> Any ideas??
>