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.