Live Chat Icon For mobile
Live Chat Icon

How can you write events for the server controls?

Platform: ASP.NET| Category: Custom Controls
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebCustomControl1
    [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : WebControl,IPostBackEventHandler
        // Defines the Click event.
        public event EventHandler Click;
        //Invoke delegates registered with the Click event.
        protected virtual void OnClick(EventArgs e)
            if (Click != null)
                Click(this, e);
        // Define the method of IPostBackEventHandler that raises change events.
            public void RaisePostBackEvent(string eventArgument)
                        OnClick(new EventArgs());
            protected override void Render(HtmlTextWriter output)
                    output.Write("<INPUT TYPE = submit name = " + this.UniqueID +  " Value = ’Click Me’ />");

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.