Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Programmatically listening for an event?

Reply
Thread Tools

Programmatically listening for an event?

 
 
George Leithead
Guest
Posts: n/a
 
      07-12-2006
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).SearchActi vated += new
WebControlLibrary.BasicSearch.SearchEventHandler(S earchResults1.PerformSearch);
}
}

 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      07-12-2006
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" <> ha scritto nel messaggio
news: ups.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).SearchActi vated += new
> WebControlLibrary.BasicSearch.SearchEventHandler(S earchResults1.PerformSearch);
> }
> }
>



 
Reply With Quote
 
 
 
 
George Leithead
Guest
Posts: n/a
 
      07-12-2006
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).P erformSearch(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" <> ha scritto nel messaggio
> news: ups.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).SearchActi vated += new
> > WebControlLibrary.BasicSearch.SearchEventHandler(S earchResults1.PerformSearch);
> > }
> > }
> >


 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      07-12-2006
You are more than welcome George,
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

"George Leithead" <> ha scritto nel messaggio
news: ups.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).P erformSearch(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" <> ha scritto nel messaggio
>> news: ups.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).SearchActi vated += new
>> > WebControlLibrary.BasicSearch.SearchEventHandler(S earchResults1.PerformSearch);
>> > }
>> > }
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What Song Are You Listening To Right Now? XhArD Media 94 01-15-2013 10:03 PM
Interruptions in live news listening Realone Player listening Thaqalain Computer Support 6 07-16-2005 02:11 PM
what are you listening to right now... HackaX0rus Media 4 07-04-2005 07:07 PM
Problems Listening To WCBS Radio CNDA Firefox 2 03-15-2005 08:50 PM
Listening for files in a directory Poul Møller Hansen Perl 2 01-16-2005 07:44 AM



Advertisments