What do you mean by centralized event handlers and why we use it?
In web applications, there are some situations when you want to associate the same event handler with different controls. Such situations can be handled by using Centralized Event handlers. A centralized event handler eliminates the need for declaring separate event handlers for different ASP.NET objects. You can create one centralized event handler that can perform appropriate action at runtime.
When you create a single event handler to respond to multiple events that should trigger different actions, you need to determine which event invoked the event handler.
2. Assign the sender argument of the event handler to the variable, casting it to the appropriate type.
3. Examine the ID property of the variable to determine which object raised the event.
The above video illustrates centralized event handler using CommandName and onCommand.
In web applications, there are some situations when you want to associate the same event handler with different controls. Such situations can be handled by using Centralized Event handlers. A centralized event handler eliminates the need for declaring separate event handlers for different ASP.NET objects. You can create one centralized event handler that can perform appropriate action at runtime.
Following is the video to demonstrate concept of Creating Centralized event handlers:
When you create a single event handler to respond to multiple events that should trigger different actions, you need to determine which event invoked the event handler.
To determine which control caused the event, you need to perform the following steps:
1. Declare a variable in the event handler with a type that matches the control that raised the event.2. Assign the sender argument of the event handler to the variable, casting it to the appropriate type.
3. Examine the ID property of the variable to determine which object raised the event.
The above video illustrates centralized event handler using CommandName and onCommand.
No comments:
Post a Comment
Press 'Ctrl + D' on your Keyboard to bookmark this page.
Still got doubts?
Submit your queries in the below comment box and we'll surely get back to you in short time!