Home All Groups Group Topic Archive Search About

How to "program" a button's click ?

Author
26 Apr 2007 10:59 AM
user
Hello,
With ASP.NET2, how to program a button's click ?
For example, I have two button and when i click the first one, i would like
that the second one will be click too (by programming) ... something like
button2.click ???

Thanks for help ..

Author
26 Apr 2007 1:39 PM
Hans Kesting
> Hello,
> With ASP.NET2, how to program a button's click ?
> For example, I have two button and when i click the first one, i would
> like
> that the second one will be click too (by programming) ... something
> like
> button2.click ???
> Thanks for help ..
>

Do you mean that both serverside handlers should be executed?
The Button2_Click handler is just a method, so nothing prevents you
from calling that from Button1_Click. Although is might be better to
have the code that you want executed for both buttons in a separate
method, that you call from both handlers.

Hans Kesting
Author
26 Apr 2007 1:39 PM
Juan T. Llibre
You don't need to actually "click" the second button.
In fact, I'd bet you don't even need a second button.


If you run the second button's click event, the page will be submitted twice,
once with the first button and the second time with the second button.

That second button probably calls a function, right ?
Just call the function with your first button and get rid of the second button.

If you still want to click a second button, you can use Javascript :

var clickbutt = document.getElementById(SecondButtonName);
if (clickbutt)
{
clickbutt.click();
}

I don't know why you'd want to do that, though.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Show quote
"user" <u***@user.com> wrote in message news:OnvVGI$hHHA.4552@TK2MSFTNGP04.phx.gbl...
> Hello,
> With ASP.NET2, how to program a button's click ?
> For example, I have two button and when i click the first one, i would like that the second one
> will be click too (by programming) ... something like button2.click ???

> Thanks for help ..
Author
26 Apr 2007 2:50 PM
Will
On Apr 26, 12:59 pm, "user" <u***@user.com> wrote:
> Hello,
> With ASP.NET2, how to program a button's click ?
> For example, I have two button and when i click the first one, i would like
> that the second one will be click too (by programming) ... something like
> button2.click ???
>
> Thanks for help ..

There is no real way to have both buttons pushed however you can
program it so that when button 1 is pressed they get the same results
that happen with button 2.

Presuming you are in visual studio or the web express version and want
to do the code on the server end you do the following, if you want to
do this all on the client end you will need to do it using ecmascript
aka javascript and that would be better asked in another group;
however the general idea would be the same.

As for on the server side go into the design view and drag a button to
the screen and double click on the first button, this will generate
the code framework needed to handle the button.

Now you will need to write the code you want to execute, do what you
want for each button in a separate function then in the area for
button 1 call both of those functions.  Then go back and drag button 2
where you want it and double click and call the function for button 2
in that place.  If you want both buttons to do the same thing then
just write one function and have both button events call it.
Author
26 Apr 2007 4:26 PM
Peter Bromberg [C# MVP]
In the Button1_Click handler you can call:
Button2_Click(null,null);

Seems like kind of a dorky way to do things though. See the other posters'
recommendations.
Peter

Show quote
"user" wrote:

> Hello,
> With ASP.NET2, how to program a button's click ?
> For example, I have two button and when i click the first one, i would like
> that the second one will be click too (by programming) ... something like
> button2.click ???
>
> Thanks for help ..
>
>
>
Author
26 Apr 2007 10:51 PM
Phil H
On 26 Apr, 17:26, Peter Bromberg [C# MVP]
<pbromb***@yahoo.yabbadabbadoo.com> wrote:
Show quote
> In the Button1_Click handler you can call:
> Button2_Click(null,null);
>
> Seems like kind of a dorky way to do things though. See the other posters'
> recommendations.
> Peter
>
> --
> Site:  http://www.eggheadcafe.com
> UnBlog:  http://petesbloggerama.blogspot.com
> Short urls & more:    http://ittyurl.net
>
>
>
> "user" wrote:
> > Hello,
> > With ASP.NET2, how to program a button's click ?
> > For example, I have two button and when i click the first one, i would like
> > that the second one will be click too (by programming) ... something like
> > button2.click ???
>
> > Thanks for help ..- Hide quoted text -
>
> - Show quoted text -

I strongly recommend that you create a separate sub-routine (or
procedure depending on source language) to execute the code contained
in the button2 click event handler and call that from both handlers.
Futhermore give at a descriptive name that helps to document its
purpose.

I know this suggestion is not original but it's the cleanest way to
implement re-usable code.

HTH
Author
27 Apr 2007 5:45 PM
user
Thanks ! i want to do it first to avoid a duplicate insert action with F5
button by click on a select bouton after click the insert button ...
Finally i used response.redirect(selfpage) to avoid the duplicate data..

Thanks again !

Show quote
"user" <u***@user.com> a écrit dans le message de
news:OnvVGI$hHHA.4552@TK2MSFTNGP04.phx.gbl...
> Hello,
> With ASP.NET2, how to program a button's click ?
> For example, I have two button and when i click the first one, i would
> like that the second one will be click too (by programming) ... something
> like button2.click ???
>
> Thanks for help ..
>
>

AddThis Social Bookmark Button