c# - Nested Masterpages and .FindControl -


On one site, I'm using only one level masterpiece and in that one page using that master, I I can do this. To access Master.FindControl ("controlName") control. works fine.

However, using the same code on the site containing two masterpap levels. Main Master and Specialist, who is Chief Master in Master Master.

Therefore, returning empty for FindControl object, on a page using specific master. When I set a breakpoint and see the page. Mester, this is showing a typical master and the typical master is showing the mastermind as the right owner, but FindControl is still unsuccessful.

When I look at the source in IE, the control is properly named, no .net mungbean is running.

Any ideas here?

TIA!

When you're nesting master pages, you will get an additional container "content" Which you need to see.

As a result, if you are trying to use FindControl from a given child page, then the general approach affects:

  label myLabel = (label ) This.Master.FindControl ("mylabel"); MyLabel.Text = "Success!";  

Since we have a nested master page, because the child has "myLabel" in the master, this control will be contained in the control.

Therefore, change this code to:

  ContentPlaceHolder ph = (ContentPlaceHolder). Master.Master.FindControl ("yourContentPane"); Label myLabel = (label) ph.FindControl ("myLabel"); MyLabel.Text = "Success!";  

and VB.NET

  Content as a page pdf.de = Direct Seite (Me.Master.Master.FindControl ("YourContentPane"), content placeholder) labeled as "MyLabel = Direct Season" (pH fund control ("my label"), label) myLabel.Text = "success!"  

The contents of the child page are loaded in the first master page control, which is then loaded in the grandparent's master page.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -