473,790 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I call an event in code?

Dom
In the days of VB, it was possible to do the following: "Call
Button1_Click() ", although there was some argument about whether this
was asking for trouble.

Is it possible to do it in CSharp? The trouble that I see is that
every event handler needs arguments. But can you do something like
"Raise Button1_Click"?

Dom

Jul 31 '07 #1
4 1721
On Jul 31, 11:05 am, Dom <dolivas...@gma il.comwrote:
In the days of VB, it was possible to do the following: "Call
Button1_Click() ", although there was some argument about whether this
was asking for trouble.

Is it possible to do it in CSharp? The trouble that I see is that
every event handler needs arguments. But can you do something like
"Raise Button1_Click"?

Dom
ControlName.Per formClick()

Jul 31 '07 #2
Dom,

An event handler is nothing more than a method. That method is called
through a delegate by the source of an event. However, there is nothing
that is preventing you from calling that method. To that end, you have to
supply the method with what it expects, in this case, the source of the
event (sender) and the EventArgs instance (or class derived from it).

Now, depending on the code in the event handler, you could possibly get
away with not providing values for those parameters (null for sender, and
default values for whatever is passed as the second parameter).

However, if you are trying to synthesize the firing of the event, then
you really should look for a method on the object itself which will fire the
event.

If you are just trying to share logic between calls, then you should
have another method which takes the parameters you need, and then just call
it from the event handler, passing the appropriate information, and the
other section of your code, again, passing the appropriate information.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dom" <do********@gma il.comwrote in message
news:11******** **************@ g4g2000hsf.goog legroups.com...
In the days of VB, it was possible to do the following: "Call
Button1_Click() ", although there was some argument about whether this
was asking for trouble.

Is it possible to do it in CSharp? The trouble that I see is that
every event handler needs arguments. But can you do something like
"Raise Button1_Click"?

Dom

Jul 31 '07 #3
Dom
On Jul 31, 11:14 am, za...@construct ion-imaging.com wrote:
On Jul 31, 11:05 am, Dom <dolivas...@gma il.comwrote:
In the days of VB, it was possible to do the following: "Call
Button1_Click() ", although there was some argument about whether this
was asking for trouble.
Is it possible to do it in CSharp? The trouble that I see is that
every event handler needs arguments. But can you do something like
"Raise Button1_Click"?
Dom

ControlName.Per formClick()
Thanks. Exactly what I wanted. I guess the "PerformCli ck" method was
added since VB people were doing it anyway.

Jul 31 '07 #4
Hi,

"Dom" <do********@gma il.comwrote in message
news:11******** **************@ g4g2000hsf.goog legroups.com...
In the days of VB, it was possible to do the following: "Call
Button1_Click() ", although there was some argument about whether this
was asking for trouble.

Is it possible to do it in CSharp? The trouble that I see is that
every event handler needs arguments. But can you do something like
"Raise Button1_Click"?
Of course you can, the event handler is just a regular method, you can call
it from code if you want.

Regarding the parameters, depending of the use you give them you can pass
null.

Jul 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4061
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: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
39
6557
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
3
11880
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 to-be-developed-function cmdOkay_Click() function as described below. 1. Create an user control that contains an OK button as below Public Class MyButton:System.Windows.Form.UserControl
2
3009
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 with arguments I need to do this as the method is being called Asynchronously from elsewhere using delegate's BeginInvoke method. The form is well created/initialized yet the messages states otherwise.
13
9787
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 is writen in the eventhandler. Is it posible to call that eventhandler from the code (not from a real selectedindexchanged on the form). So, I don't have to call that code twice.
4
4294
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 I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to have 'gotcha's':
6
12289
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I would like to do this by defining a NewFunc() that is different in each (code-behind) page which is called by the standard 'New' button in the toolbar. How can I get this to work? So far I have the following (which doesnt work). When the user...
22
3199
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 If statement to see if a file was already playing and if so executes some code to stop the previous file from playing among other things. There's also a "stop" button on the form that contains the exact same code. Obviously it would be easier if...
4
3223
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 the page can carry on rendering whilst the call is taking place and also returning the ASP.NET worker thread to service another page request (for scalability). I have developed a very basic asynchronous object (for testing, that reproduces the same...
3
7426
by: Ignacio Machin | last post by:
How can I call an event from another event: I want to call : DropDownList_SelectedIndexChanged in: Page_Load
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.