FindControl and ContentPlaceHolders

Mar 07 2008

Suppose you have a MasterPage with two ContentPlaceHolders, and you need to reference a control from one ContentPlaceHolder in a control in the other ContentPlaceHolder. You can’t use the normal control id, since ASP.Net will complain that it can’t find the control living in the other ContentPlaceHolder.

The solution is very simple: just prefix the referenced control id with the id of the ContentPlaceHolder it’s living in, seperated by a $ sign. Like this:

SomeContentPlaceholder$SomeReferencedControl

And now ASP.Net will happily find the control and continue it’s business as planned. It even works for UpdatePanels across different ContentPlaceHolders.

For example, you have a form in a left ContentPlaceHolder, but you want to display the validators in another ContentPlaceHolders. Here’s how to do that:



	Required Text: 




	

Easy peasy, ain’t it?

One response so far

  1. Man! U saved my life a bit! Thank you!

    My code is here

Leave a Reply