Thursday, August 13, 2009

Access Master page events from Content page

The following are the steps to be taken to access a master page's event from a content page.

1. Create a drop down list in the Master page.

2. Create an Event handler for SelectIndexChanged event.

3. Define an event in the Master page for the Dropdowns select index changed with the above signature.

4. Subscribe to the event in the contentpage that care about the changing of the ddl.



Here is the code to subscribe the event from the content page.
protected void Page_Init(object sender, EventArgs e)
{
Master.EventHandlerName += new CommandEventHandler(MasterPageEventName);
}

protected void MasterPageEventName(object sender, CommandEventArgs e)

{

string text = e.CommandName;

string value = e.CommandArgument.ToString();

}

NOTE: We can use delegates as well.

No comments:

Post a Comment