Creating Custom Events in a Custom Control RRS feed

  • Question

  • User-267673232 posted


    I have started making custom controls till now i can call javascript functions from my custom controls, but then i thought how can i add an event in a custom control.

    For E.g : DropDownlistSelectedIndexChanged,Grid_Editing,Deleting onClick etc. Means When i double click from the designer then designer should generate an event in Code-Behind file.


    So Please tell how can i create a custom event in a Custom Control.




    Saturday, December 26, 2009 1:47 PM


  • User-361266631 posted

    Hello Ricky,

    What follows is a UserControl with a CoolEvent. You can fire the CoolEvent from codebehind by calling the OnCoolEvent method.

    <%@ Control Language="C#" ClassName="UserControlWithCoolEvent" %>
    <script runat="server">
    	public event EventHandler CoolEvent;
    	protected void OnCoolEvent(EventArgs e)
    		if (CoolEvent != null)
    			CoolEvent(this, e);

    For more details you can have a look here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 27, 2009 3:57 AM