Sender in. net Control event,. net Control sender

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.