Wednesday, January 6, 2010

how do you programmatically raise a button-click event


You can use the following C# code raise the event:

((IPostBackEventHandler)Button1).RaisePostBackEvent(null);

This code will raise the button-click event for Button1 just as though the user clicked the button. Since we are passing a null as the EventArgs for the event, the registered methods must not attempt to do anything with it. Or, you could create an EventArgs object and pass it.


No comments: