Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to "program" a button's click ?

Reply
Thread Tools

How to "program" a button's click ?

 
 
user
Guest
Posts: n/a
 
      04-26-2007
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 ..


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      04-26-2007
> 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


 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      04-26-2007
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/
===================================
"user" <(E-Mail Removed)> wrote in message news:OnvVGI$(E-Mail Removed)...
> 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 ..



 
Reply With Quote
 
Will
Guest
Posts: n/a
 
      04-26-2007
On Apr 26, 12:59 pm, "user" <(E-Mail Removed)> 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.


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      04-26-2007
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 ..
>
>
>

 
Reply With Quote
 
Phil H
Guest
Posts: n/a
 
      04-26-2007
On 26 Apr, 17:26, Peter Bromberg [C# MVP]
<(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
user
Guest
Posts: n/a
 
      04-27-2007
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 !

"user" <(E-Mail Removed)> a écrit dans le message de
news:OnvVGI$(E-Mail Removed)...
> 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 ..
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
click click click Andy Morrison Computer Support 7 12-20-2007 06:50 AM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
button click event being called twice on click mike parr ASP .Net 1 05-20-2004 04:02 PM
Datalist selects Item after first click, but does apply the SelectedItemTemplate after the second click only Dirk Meusel ASP .Net 1 08-19-2003 09:56 AM



Advertisments