Hi All,
I have a server button control. How to pass arguments in the onclick event of the button.
By default, the button takes two arguments, how to pass a third argument.
Murali
Windows Forms General
Hi All,
I have a server button control. How to pass arguments in the onclick event of the button.
By default, the button takes two arguments, how to pass a third argument.
Murali
delegate void MyEventHandler(object source, EventArgs e, MyExtra extra);
public event MyEventHandler Click;
class MyEventArgs : EventArgs {
private MyExtra extra;
public MyEventArgs(MyExtra extra) : base() {
this.extra = extra;
}
public MyExtra {
get { return this.extra; }
set { this.extra = value; }
}
}
private void RaiseClickEvent() {
if (Click != null) {
MyEventArgs args = new MyEventArgs(myExtraInstance)
Click(this, args);
}
}
Hi,
Thank you very much. I think this will defintely solve my problem.
Murali
hi,
this is same problem with me. but i could not understand your code.
Have u complete code
or
can u define it by an example
thnx
public MyButton : Button
{
protected override OnClick(EventArgs e)
{
EventHandler handler = (EventHandler) base.Events[EventClick];
if (handler != null)
{
MyClickEventArgs myClickEventArgs = new MyClickEventArgs(e);
// set the extra data....
handler(this, myClickEventArgs);
}
}
}
public void button_Click(object sender, EventArgs e)
{
MyClickEventArgs myClickEventArgs = e as MyClickEventArgs;
if (myClickEventArgs != null)
{
// do something with the extra data....
}
}