Click here to Skip to main content
15,893,381 members
Articles / Web Development / HTML

How to Create an Event for a User Control

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
16 Oct 2009CPOL2 min read 86K   1.9K   24  
Article on how to create a user defined event for a user control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ctrlCalculator : System.Web.UI.UserControl
{
    public delegate void CalculationInProgress(object sender, OperationEventArgs e);
    public event CalculationInProgress Calculating;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnPerformOperation_Click(object sender, EventArgs e)
    {
        this.Calculating(this, new OperationEventArgs(Operation.Addition, Convert.ToDecimal(this.txtValue1.Text) + Convert.ToDecimal(this.txtValue2.Text)));
        this.Calculating(this, new OperationEventArgs(Operation.Subtraction, Convert.ToDecimal(this.txtValue1.Text) - Convert.ToDecimal(this.txtValue2.Text)));
        this.Calculating(this, new OperationEventArgs(Operation.Multiplicaiton, Convert.ToDecimal(this.txtValue1.Text) * Convert.ToDecimal(this.txtValue2.Text)));
        this.Calculating(this, new OperationEventArgs(Operation.Division, Convert.ToDecimal(this.txtValue1.Text) / Convert.ToDecimal(this.txtValue2.Text)));
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Arab Emirates United Arab Emirates
Faraz is working as a Senior Software Engineer for a company located in Sharjah, UAE. He likes developing new applications with the latest technologies. Mostly reponsible for web applications using Microsoft.Net. He has done MCPD so far. Other than work play guitars, sing and play PSP.

Comments and Discussions