What does the sender mean in asp +?

Source: Internet
Author: User

Tofu is made of excellent products
Http://www.asp888.net bean curd technology station

Friends who often write asp + programs must have seen such code Button_Click (Object Sender, EventArgs E)
But what does Sender mean? What is his usefulness?
Many people just call it mechanically. Today, tofu will tell you what this Sender means?
Actually, this Sender is used when we process the object that triggers this event in this event. That is to say
Sender is the button to be clicked. Let me give you an example. You may be clear about it.
<Input type = "submit" id = "a1" value = "1" OnServerClick = "Submit_Click" runat = "server">
<Input type = "submit" id = "a2" value = "2" OnServerClick = "Submit_Click" runat = "server">
<Input type = "submit" id = "a3" value = "3" OnServerClick = "Submit_Click" runat = "server">
<Input type = "submit" id = "a4" value = "4" OnServerClick = "Submit_Click" runat = "server">
These are four Submit buttons. The events triggered by them are the same event. How can we differentiate them? See the following Code
Public void Submit_Click (Object sender, EventArgs E)
{
Switch (Control) sender). ID)
{
Case "a1": showmsg. Text = "" Haha 1; break;
Case "a2": showmsg. Text = "" Haha 2; break;
Case "a3": showmsg. Text = "" Haha 3; break;
Case "a4": showmsg. Text = "" Haha 4; break;
}
}
</Script>

<Asp: Label id = showmsg runat = server/>
The code itself is meaningless, but it illustrates a problem. Maybe this is the meaning of this article.


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.