|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Programmatically listening for an event?I have the following in an ASPX page, that is an event listener, that works fine. BasicSearch1.SearchActivated += new myWebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); However, I would like to change the ASPX page to not assume the name of the control, but instead listen to the event programmatically. I tried the below, which does compile and resolve correctly, however, it does not appear to be 'listening' to the event and does not get triggered! foreach (Control ctrl in Page.Controls) { if (ctrl.GetType() == typeof(myWebControlLibrary.BasicSearch)) { // This SHOULD have worked! But it doesnt appear to indicate that it is listening! ((myWebControlLibrary.BasicSearch)ctrl).SearchActivated += new WebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); } } hi George, you have to go deeper in the hierarchy. The control you are
looking for may not be a direct child of your pages control collection but a child control of the form control in the page. If the control you are looking for is further nested within another control, then its up to you to dig further down the hierarchy and find it. Currently the code is not executing because you are searching in the wrong place where the control is not contained. follow the tutorial here : http://msdn2.microsoft.com/en-us/library/yt340bh4.aspx Alessandro Zifiglio http://www.AsyncUI.net Show quoteHide quote "George Leithead" <george.leith***@gmail.com> ha scritto nel messaggio news:1152691059.892814.139690@75g2000cwc.googlegroups.com... > Hi, > > I have the following in an ASPX page, that is an event listener, that > works fine. > > BasicSearch1.SearchActivated += new > myWebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); > > However, I would like to change the ASPX page to not assume the name of > the control, but instead listen to the event programmatically. I tried > the below, which does compile and resolve correctly, however, it does > not appear to be 'listening' to the event and does not get triggered! > > foreach (Control ctrl in Page.Controls) > { > if (ctrl.GetType() == > typeof(myWebControlLibrary.BasicSearch)) > { > // This SHOULD have worked! But it doesnt appear to > indicate that it is listening! > ((myWebControlLibrary.BasicSearch)ctrl).SearchActivated += new > WebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); > } > } > Alessandro,
That was it ...spot on. Thanks. In the interest of information sharing, my code ended up as: foreach (Control ctrl in Page.Controls) { foreach (Control chldControl in ctrl.Controls) { if (chldControl.GetType() == typeof(myWebControlLibrary.SearchResults)) ((myWebControlLibrary.SearchResults)chldControl).PerformSearch(this, new SearchActivatedEventArgs(queryExpression, coveoInstanceName, coveoCollectionNames, useWildcards)); } } George Alessandro Zifiglio wrote: Show quoteHide quote > hi George, you have to go deeper in the hierarchy. The control you are > looking for may not be a direct child of your pages control collection but a > child control of the form control in the page. If the control you are > looking for is further nested within another control, then its up to you to > dig further down the hierarchy and find it. > Currently the code is not executing because you are searching in the wrong > place where the control is not contained. > > follow the tutorial here : > http://msdn2.microsoft.com/en-us/library/yt340bh4.aspx > > Alessandro Zifiglio > http://www.AsyncUI.net > "George Leithead" <george.leith***@gmail.com> ha scritto nel messaggio > news:1152691059.892814.139690@75g2000cwc.googlegroups.com... > > Hi, > > > > I have the following in an ASPX page, that is an event listener, that > > works fine. > > > > BasicSearch1.SearchActivated += new > > myWebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); > > > > However, I would like to change the ASPX page to not assume the name of > > the control, but instead listen to the event programmatically. I tried > > the below, which does compile and resolve correctly, however, it does > > not appear to be 'listening' to the event and does not get triggered! > > > > foreach (Control ctrl in Page.Controls) > > { > > if (ctrl.GetType() == > > typeof(myWebControlLibrary.BasicSearch)) > > { > > // This SHOULD have worked! But it doesnt appear to > > indicate that it is listening! > > ((myWebControlLibrary.BasicSearch)ctrl).SearchActivated += new > > WebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); > > } > > } > > You are more than welcome George,
Regards, Alessandro Zifiglio http://www.AsyncUI.net Show quoteHide quote "George Leithead" <george.leith***@gmail.com> ha scritto nel messaggio news:1152700585.701982.63980@p79g2000cwp.googlegroups.com... > Alessandro, > > That was it ...spot on. Thanks. > > In the interest of information sharing, my code ended up as: > > foreach (Control ctrl in Page.Controls) > { > foreach (Control chldControl in ctrl.Controls) > { > if (chldControl.GetType() == > typeof(myWebControlLibrary.SearchResults)) > ((myWebControlLibrary.SearchResults)chldControl).PerformSearch(this, > new SearchActivatedEventArgs(queryExpression, coveoInstanceName, > coveoCollectionNames, useWildcards)); > } > } > > > George > > Alessandro Zifiglio wrote: > >> hi George, you have to go deeper in the hierarchy. The control you are >> looking for may not be a direct child of your pages control collection >> but a >> child control of the form control in the page. If the control you are >> looking for is further nested within another control, then its up to you >> to >> dig further down the hierarchy and find it. >> Currently the code is not executing because you are searching in the >> wrong >> place where the control is not contained. >> >> follow the tutorial here : >> http://msdn2.microsoft.com/en-us/library/yt340bh4.aspx >> >> Alessandro Zifiglio >> http://www.AsyncUI.net >> "George Leithead" <george.leith***@gmail.com> ha scritto nel messaggio >> news:1152691059.892814.139690@75g2000cwc.googlegroups.com... >> > Hi, >> > >> > I have the following in an ASPX page, that is an event listener, that >> > works fine. >> > >> > BasicSearch1.SearchActivated += new >> > myWebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); >> > >> > However, I would like to change the ASPX page to not assume the name of >> > the control, but instead listen to the event programmatically. I tried >> > the below, which does compile and resolve correctly, however, it does >> > not appear to be 'listening' to the event and does not get triggered! >> > >> > foreach (Control ctrl in Page.Controls) >> > { >> > if (ctrl.GetType() == >> > typeof(myWebControlLibrary.BasicSearch)) >> > { >> > // This SHOULD have worked! But it doesnt appear to >> > indicate that it is listening! >> > ((myWebControlLibrary.BasicSearch)ctrl).SearchActivated += new >> > WebControlLibrary.BasicSearch.SearchEventHandler(SearchResults1.PerformSearch); >> > } >> > } >> > >
Setting Properties in a Composite Control...
Repeater and text boxes inside how to change labelvalue when deleting row in gridview? Can't install iewebcontrols.msi - error "webctrl_client is unavailable" Multi-line textbox scrolled to bottom? Problem handling event in a button inside a Datalist How to put an image in a GridView textfield not recognized in gridview passing variable to sql statement in asp.net 2.0? menu control with XML file |
|||||||||||||||||||||||