469,927 Members | 1,910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Call Event

How can I call an event from another event:
I want to call :
DropDownList_SelectedIndexChanged
in:
Page_Load
Mar 7 '07 #1
3 7288
This is somebody using Ignacio's machine, right?
Generally you do not "call" an event; the event is triggered by the action
of the dropdownlist having a selection changed. Maybe you could be more
clear about exactly what the goal is?
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Ignacio Machin" wrote:
How can I call an event from another event:
I want to call :
DropDownList_SelectedIndexChanged
in:
Page_Load
Mar 7 '07 #2
If you have coded an "event handler" for DropDownList_SelectedIndexChanged,
then move that code into a separate method.

Have DropDownList_SelectedIndexChanged call that method (ie. a one-liner).

Have your Page_Load call the same method.

NOTE: If the method needs "arguments" then both callers need to provide
whatever is required - this is largely one of the reasons why you do not
call event handlers manually because you would be required to provide the
Sender and EventArgs arguments, for example.

Kevin

"Ignacio Machin" <ignacio.machin AT dot.state.fl.uswrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
How can I call an event from another event:
I want to call :
DropDownList_SelectedIndexChanged
in:
Page_Load

Mar 7 '07 #3
Ignacio Machin wrote:
How can I call an event from another event:
I want to call :
DropDownList_SelectedIndexChanged
in:
Page_Load

I'd expect the dropdownlist to actually fire that event itself if the
SelectedIndex property changed.

If, on the other hand, you want to execute the same code as changing the
SelectedIndex property does, the correct way (in my opinion) would be to
take the code out of that event handler and place it in a separate
method, ie. "UpdateRelatedData" or something, and then call that method
from both DropDownList_SelectedIndexChanged and Page_Load.

If you really don't want to do that, the "correct" way to execute the
same code would be to:

1. Call the OnSelectedIndexChanged method on the dropdownlist, if that
method is public (mostly isn't, so go to 2.)
2. Call the method you attached to the event directly, ie. call
DropDownList_SelectedIndexChanged, and provide any necessary parameter
values to it.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
Mar 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ricky W. Hunt | last post: by
4 posts views Thread by Paul | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.