[SOLVED] C# pass additional parameter to an event handler while binding the event at the run time


I have a link button which have a regular click event :

protected void lnkSynEvent_Click(object sender, EventArgs e)

And I bind this event at the runtime :

lnkSynEvent.Click += new EventHandler(lnkSynEvent_Click);

Now I need the function to accept additional argument:

protected void lnkSynEvent_Click(object sender, EventArgs e, DataTable dataT)

And pass the same as parameter while binding this event :

lnkSynEvent.Click += new EventHandler(lnkSynEvent_Click, //somehow here);

Not sure how to achieve this.
Please help.

Thanks in advance.



You can use anonymous delegate for that:

lnkSynEvent.Click += 
         new EventHandler((s,e)=>lnkSynEvent_Click(s, e, your_parameter));

Answered By – alex

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *