How to communicate between ASP.net custom controls -
i'm using 2 custom controls. 1 gathers criteria search, , other displays list. these 2 controls need remain seperate time being.
what best method of transfering data search control, list control?
i'm thinking of viewstate, session or wrapping both within updatepanel , using custom events??
maybe can create delegate , event pass list of searchvalues? way can add or multiple display controls in case ever becomes necessary.
note quick sample code should optimized/improved.
public class searchcontrol { public delegate void searcheventhandler(object sender, dictionary<string, string> searchvalues); public event searcheventhandler onsearch; public searchcontrol() { btnsearch.click += new eventhandler(search); } protected void search(object sender, eventargs e) { if (onsearch != null) { dictionary<string, string> searchvalues = new dictionary<string, string>(); searchvalues.add("name", "john"); searchvalues.add("age", "24"); onsearch(this, searchvalues); } } } public class displaycontrol { public void showresults(dictionary<string, string> searchvalues) { // logic here... } } public class yourwebpage { searchcontrol searcher = new searchcontrol(); displaycontrol displayer = new displaycontrol(); public yourwebpage() { searcher.onsearch += new searchcontrol.searcheventhandler(searcher_onsearch); } public void searcher_onsearch(object sender, dictionary<string, string> searchvalues) { displayer.showresults(searchvalues); } }
Comments
Post a Comment