Search

Friday, May 30, 2014
0 comments

How to call event in page load method and example of EventHandler class

11:25 PMFriday, May 30, 2014
If you want to add event at run time like click event in page load method. For this types of problem you can use EventHandler class. Create a object of this class also pass new method as a parameter.

Source Code

<div>
    
        <asp:Button ID="B1" runat="server" CommandName="Add" Text="Button" />
    
    </div>

    Business Code


    public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        B1.Click += new System.EventHandler(this.calculate);
    }
    protected void calculate(object sender, System.EventArgs e)
    {
        switch (((Button)sender).CommandName)
        {
            case "Add": Response.Write("hello");
                break;
        }
    }

}
Code Generate the following output
How to call event in page load method and example of EventHandler class
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top