0

I have a Top Master page let say "A" in which i have a button and a textbox. Then there is another Master page "B" which is Child of "A". Then there is a page.aspx which is child of "B". so basically I want to send the value of Text of in my page.aspx when the button (which is in A MasterPage) is clicked. Following some of the links I did something like this. in A master page

 public Button PropertyMasterButton
{
    get { return SearchButton; }
}

then if I do this is B master page I can successfully create its event in B

protected void Page_Init(object sender, EventArgs e)
{

  Master.PropertyMasterButton.Click += new EventHandler(SearchButton_Click);


}

and then I create the Event function

public void SearchButton_Click(object sender, EventArgs e)
{
     Response.Redirect("SearchResults.aspx");

}

and it works fine. theproblem occurs when I take it to page.aspx "C" which is child of B.

Now i have no idea how to take it to the 3rd page i.e "C" :/

i'll really appreciate any help, I'm stuck here

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by AleMonteiro
0

There's probably a more elegant way, but I use this one:

        /// <summary>
        /// Finds parent master page by name
        /// </summary>
        /// <param name="masterPage">MasterPage to search on</param>
        /// <param name="name">Name to find</param>
        /// <returns>MasterPage</returns>
        public static MasterPage getMasterPage ( System.Web.UI.MasterPage masterPage, string name )
        {
            if ( masterPage == null )
            {
                return null;
            }
            if ( masterPage.GetType().Name.ToLower().IndexOf( name ) > -1 )
            {
                return masterPage;
            }
            else if ( masterPage.Master != null )
            {
                return getMasterPage( masterPage.Master, name );
            }
            else
            {
                return null;
            }
        }

To call it

((YourMasterPageType)getMasterPage(this.Master), "MasterB").PropertySearchButton...

Hope it helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.