A web project I am developing has nested Master Pages.
Within Main Master Page has two ContentPlaceHolder with IDs ContentPlaceHolder1 and ContentPlaceHolder2 respectively.
Within ContentPlaceHolder1 resides another Master Page which I will name it as Second Master Page for an easy usage. The Second Master Page has one ContentPlaceHolder with ID called ContentPlaceHolder2.
Under the Second Master Page's ContentPlaceHolder2 is the page I'm working on which I will name it as XX.aspx.
XX.aspx contains custom composite controlsthat are checkboxes and dropdownlists.
What I would like to do is: after clicking on SAVE button, the data related to the checked checkboxes and its related dropdownlist options will be stored in the database.
The VIEWSTATE of the custom controls are kept on POSTBACK and all I need to do is to look for those custom controls on XX page and get the data.
I first tried to get content place holder control on XX page by using the following code:
ContentPlaceHolder _content = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder2");
However, that code returns NULL.
After figuring out what it does for some times, I changed the code as:
ContentPlaceHolder _pcontent = (ContentPlaceHolder)Master.Master.FindControl("ContentPlaceHolder1");
ContentPlaceHolder _content = (ContentPlaceHolder)_pcontent.FindControl("ContentPlaceHolder2");
if (_content != null)
{
x x x
}
Now I understand that in order to avoid the ambiguous ContentPlaceHolder ID names in nested Master Page, I shall start searching from the top parent Master Page.
Now I'm satisfied that I can retrieve data from the controls on my XX page :)
Thursday, 5 July 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment