First, define the delegate (delegate) on the master page ):
Namespace notsee. Web. Manage
{
Public partial class SYS: system. Web. UI. masterpage
{
Public Delegate void elementselectedchangehandler ();
// Instantiate the delegate, which is actually an attribute
Public elementselectedchangehandler elementselectedchange {private get; set ;}
Protected void page_load (Object sender, eventargs E)
{// Notsee.info Technical Exchange
}
// Buttons in the master
Protected void btnsearch_click (Object sender, eventargs E)
{
If (elementselectedchange! = NULL)
{
Elementselectedchange ();
}
}
}
}
For example, on the notsee. aspx content page, we need to specify a method that matches the delegate signature in the notsee. ASPX page:
Namespace WMS. Web. Manage
{
Public partial class notsee: system. Web. UI. Page
{
Master. elementselectedchange = This. elementselectedchange;
Protected void page_load (Object sender, eventargs E)
{// Notsee.info Technical Exchange
}
Void elementselectedchange ()
{
// Your solution
}
}
}
In summary, here we use the principle of delegation (the design principle of dependency inversion. That is, to define a general framework for future generations to addCode).