complex event bubbling problem

  • Thread starter Thread starter Wee Bubba
  • Start date Start date
W

Wee Bubba

the following event handler checks to see if any parent control has
attached to the event 'SearchItemSelect'. i use it for event bubbling
whenever one of my search items has been selected and at the moment i
am calling this from a repeater's ItemCommand event handler:

protected void OnSearchItemSelect(EventArgs e)
{
if (SearchItemSelect != null)
{
SearchItemSelect (this, e);
}
}

i now want to call this from within a different function, NOT an event
handler. basically if the user's search returns only one hit I don't
want to display a repeater I just want to bubble an event up to the
mother page straight away. i tried this:

OnSearchItemSelect();

but i get the error message "No overload for method
'OnSearchItemSelect' takes '0' arguments. i realise that ive got to
pass it a variable of type 'e'. But what do I pass it as I am not
calling it from within a repeater's event handler anymore but just
from a general method? how can i overload my event?
 
Wes:

You can create the EventArgs instance yourself, i.e:

EventArgs e = new EventArgs();
OnSearchItemSelect(e);

or simply

OnSearchItemSelect(new EventArgs());

Since the EventArgs class does not have information (state) about the
event to pass along, this should work fine. Other event argument
objects contain information about the type of event and who the event
is coming from, but EventArgs is pretty braindead.

HTH,
 
Does it basically make any difference if you treat it as an ordinary method
call? You could call it:

OnSearchItemSelect(EventArgs.Empty);

but certainly if you work with event bubbling as it really works, the type
of the event argument should be CommandEventArgs (in
System.Web.UI.WebControls) namespace. If it needs that, just instantiate
System.Web.UI.WebControls.CommandEventArgs with proper command event data
and pass it to the method.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke





Wee Bubba said:
the following event handler checks to see if any parent control has
attached to the event 'SearchItemSelect'. i use it for event bubbling
whenever one of my search items has been selected and at the moment i
am calling this from a repeater's ItemCommand event handler:

protected void OnSearchItemSelect(EventArgs e)
{
if (SearchItemSelect != null)
{
SearchItemSelect (this, e);
}
}

i now want to call this from within a different function, NOT an event
handler. basically if the user's search returns only one hit I don't
want to display a repeater I just want to bubble an event up to the
mother page straight away. i tried this:

OnSearchItemSelect();

but i get the error message "No overload for method
'OnSearchItemSelect' takes '0' arguments. i realise that ive got to
pass it a variable of type 'e'. But what do I pass it as I am not
calling it from within a repeater's event handler anymore but just
from a general method? how can i overload my event?



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
thanks a lot scott. that worked a treat. ive been trying to work that
one out all day!!! nice one matey!!! :D
 
also scott, whilst i got ya, i posted another question about dataList
control ID's. i was wondering if you knew the answer to that one
too... :wink:
 
Back
Top