Case:The ASPX page has a control. You want to click the control button to perform some operations to obtain a datatable and bind the datatable to the Data Control on the page.
Control CS file:
1. Define proxy
Public Delegate Void Retrievetargetshandler ( Object Sender, retrieveeventargs E );
Public ClassRetrieveeventargs: eventargs
{
PrivateDatatable resulttable;
PublicDatatable resulttable
{
Get{ReturnResulttable ;}
}
PublicRetrieveeventargs (datatable RET)
:Base()
{
This. Resulttable=RET;
}
}
2. Define events
Public Event Retrievetargetshandler retrievetargets;
3. When you click the control button,
Protected Void Btnsearchbyconditions_click ( Object Sender, eventargs E)
{
Datatable dt = New Datatable ();
//
Retrievetargets ( This , New Retrieveeventargs (DT ));
}
In page_load of the aspx page,Instantiate the proxy and specify the processing method.
This . Targetsearchbyconditions1.retrievetargets + = New Retrievetargetshandler (targetsearchbyconditions1_retrievetargets );
VoidTargetsearchbyconditions1_retrievetargets (ObjectSender, retrieveeventargs E)
{
Datatable dt=E. resulttable;
Response. Write ("Yes. Good!");
}
In. net1.1,
If you want your class to triggerEventnameEvent, you need the following elements.
- the class that holds event data, named eventname eventargs. This class must be exported from system. eventargs.
- event Delegate, named eventname eventhandler.
- the class that triggers the event. This class must provide:
- event declaration.
[C #] public event eventname eventhandler eventname ; [Visual Basic] public event eventname as eventnameeventhandler
- Method for triggering the event, named on eventname .