473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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 7406
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
13
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
22
by: Ricky W. Hunt | last post by:
First, the subject probably doesn't use the correct terms but I'm not sure what it's called in VB. I'm writing a media player app. The subroutine that handles the "open file" button contains an...
7
by: Bonzo | last post by:
>From within a function, I want to pass a/some parameters to another function, AND all arguments, passed into this function. e.g. function firstFunction(){ //this function may have been...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.