Search

Thursday, May 29, 2014
0 comments

Multiple Events call same event Handler in ASP.NET

6:49 AMThursday, May 29, 2014
In ASP.NET,  you can connect multiple Events with same event handler. If you thing about it, this types of code reduce space complexity as well as time complexity. If you use events with separate events handler then take more time. Like

<div>
    Both Event and methods name are same, both call to same handler.<br />
&nbsp;<asp:Button ID="Button1" runat="server" Text="First Button" 
            onclick="Button1_Click" /><br />
         <asp:Button ID="Button2" runat="server" Text="Second Button" onclick="Button1_Click" /><br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
In my previous article, we have already discussed about it, which is how to determine which web server control is raised.

Business Logic Code

 protected void Button1_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        Label1.Text = button.Text;
    }

Code generate the following output

Multiple Events call same event Handler in ASP.NET

Multiple Events call same event Handler in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top