How to insert an event to the aspx.cs page. I have one asp:button and i wish to add an event of that button in the aspx.cs page. how it done
Just add the following to your .cs file, and amend according to whatever event you are looking to raise.
public delegate void MyEvent(myParams);
public event MyEvent AnEvent;
If it just to handle the click event of your button you can just double click the button and it will automatically take you into the OnClick event in the .cs file.
At compile time, add the text:
OnClick="MethodName"
into the button declaration. MathodName is what gets called when the event is raised (in my example, the Click event).
To dynamically do this, look up the C# or VB.NET syntax for adding and removing event handlers. I think you will also have to ensure ViewState is saved or else the handlers will disappear on the first submit.
Assume that you have a button like that :
<asp:Button runat="server" ID="myButton" />
You can add Click event at your code-behind like that :
myButton.Click += new EventHandler(myButton_Click);
Or you can specify your event at design like that :
<asp:Button runat="server" ID="myButton" OnClick="myButton_Click" />