Sender in. net Control event,. net Control sender
private void button2_Click(object sender, RoutedEventArgs e){}
I recently read about WPF. I will review that. net is used every day, but it is not a very important object ---- sender.
Q: What is sender?
A: events in all server controls will exist (probably too absolute, most of them will). sender refers to the control that triggers the event.
Private void button2_Click (object sender, RoutedEventArgs e) {Button btn = (Button) sender; // method 1 btn. Content = "kick ME! @ "; // Button2.Content =" kick ME "; // method 2}
The following describes the core of sender. What is the event-triggered control?
There are two buttons on the interface (this is a WPF program, when both buttons are bound with a click event button2_Click button ).
If you change the name of the button according to method 1 of the button2_Click event. Click "button 1" to change to "kick ME! @ ", Click" button 2 "to change to" kick ME! @ ", This indicates that sender refers to the control that triggers the event!
If you change the name of the button according to method 2 of the button2_Click event. Clicking "button 1" will make button 2 "kick ME! @ ", Click" button 2 "and there will be no response
How to Use sender in net?
Sender is a parameter, which is generally a parameter of the object type. By default, it automatically constructs a complete parameter list without manual configuration.
Net, the control event is not executed
On the Design page, click DropDownList1 and select autopostback. This option is not selected by default, so you do not need to send data back to the server.