c# - Event handler reference from utility class -


i have method i'm putting in each page make, know there should way move single place ease of maintenance , simplicity. i'm not sure how should handle event handler. event handler needs on each page, how pass in reference page can reference event handler?

private void insertlinkbutton(string text, string id, updatepanel updatesummary)     {         linkbutton link = new linkbutton();         link.text = text;         link.click += new eventhandler(link_click);   <------         link.causesvalidation = false;         asyncpostbacktrigger trigger = new asyncpostbacktrigger();         trigger.controlid = link.id = "link" + id;         trigger.eventname = "click";         utils.tag(link, placeholdersummary);         updatesummary.triggers.add(trigger);     } 

why not pass event handler method argument?

private void insertlinkbutton(string text, string id, updatepanel updatesummary,                               eventhandler clickhandler) {     linkbutton link = new linkbutton();     link.text = text;     link.click += clickhandler;     ... } 

call with:

insertlinkbutton("text", "id", updatepanel, link_click); 

(assuming link_click method name.)


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -