473,386 Members | 1,846 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,386 software developers and data experts.

button_click

Is this the correct code to have one button execute the code of anothe rbutton?

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printToolStripMenuItem.Click += new EventHandler(
buttonLoad_Click);
}
Mar 9 '07 #1
4 1923
A button's "code" is just a method. You can just call the method directly
if you need it.
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
buttonLoad_Click();
}


"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AA**********************************@microsof t.com...
Is this the correct code to have one button execute the code of anothe
rbutton?

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printToolStripMenuItem.Click += new EventHandler(
buttonLoad_Click);
}

Mar 9 '07 #2
I get an error:
No overload for buttonLoad_Click(); takes 0 arguments
"Scott M." wrote:
A button's "code" is just a method. You can just call the method directly
if you need it.
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
buttonLoad_Click();
}

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AA**********************************@microsof t.com...
Is this the correct code to have one button execute the code of anothe
rbutton?

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printToolStripMenuItem.Click += new EventHandler(
buttonLoad_Click);
}


Mar 9 '07 #3
You'll need to supply arguments for the arguments that the code you are
calling is expecting.

You can pass the current arguments to the called method like this:
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
buttonLoad_Click(sender, e);
}
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
>I get an error:
No overload for buttonLoad_Click(); takes 0 arguments
"Scott M." wrote:
>A button's "code" is just a method. You can just call the method
directly
if you need it.
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
buttonLoad_Click();
}

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AA**********************************@microso ft.com...
Is this the correct code to have one button execute the code of anothe
rbutton?

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printToolStripMenuItem.Click += new EventHandler(
buttonLoad_Click);
}



Mar 9 '07 #4
Chris wrote:
Is this the correct code to have one button execute the code of anothe rbutton?

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printToolStripMenuItem.Click += new EventHandler(
buttonLoad_Click);
}
That code would add an event handler every time you click the button.
That means that the first time you click the button, the method is not
called, the second time you click the button the method is called once,
the thrird time you click the button the method is called twice, and so on.

Just change the Click property of the button to use the buttonLoad_Click
method instead of the printToolStripMenuItem_Click method.

Perhaps also you should change the name of the method to reflect what it
actually does instead of buttonLoad_Click, as it no longer only handles
that event.

--
Göran Andersson
_____
http://www.guffa.com
Mar 9 '07 #5

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

Similar topics

0
by: Jason Huang | last post by:
Hi, What I want to do here is in the asp.net C#, when I click a button then some sorts of validation will be checked, then it will call a javascript function to open another webform. Would...
1
by: Paul Aspinall | last post by:
Hi I have a form with a button on it. It seems that when I click the button, it causes Form_load to fire, before the Button_Click procedure Does anyone know why?? Thanks
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
2
by: Frank Schumacher | last post by:
Hi Folks, I have a problem with the order of events fired by ASP.NET. I found many articles which explaining the lifecycle of a site, but I found none which took the event from a Control on the...
3
by: I am Sam | last post by:
Please help. I'm dying here and pulling out the last few remaining elements of my hair over this. I have built a form that will identify and authenticate users. I keep getting the following...
9
by: gaddoznntp | last post by:
Hi all, I've a server button handling a button_click procedure. If the client user clicks the button, the page causes the postback and the button_click procedure is fired. Then, if the user...
13
by: Matt | last post by:
I am trying to call a recursive subroutine within a Button_Click event. How can I do this? I tried to create a seperate Function() but it will not allow me to use any variables that I created in...
3
by: charles | last post by:
Hi: In my page I need to re-start a thread. I put the code into a Button_Click(sender, e) handler. When I click the button, it works. Then I call this handler inside a timer's handler...
0
by: John | last post by:
I am loading my controls dynamically into my asp.net page. When I click on a button on one of those user controls then page reloads and I need to reload the page based on what has happened in the...
8
by: Marine | last post by:
Hi, Sorry i'm a newbie with Asp.net, here is my problem : private void Page_Load(object sender, System.EventArgs e) { if (IsPostBack) { Label1.Text = (string)Session; } } private void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.