How to "program" a button's click ?

Discussion in 'ASP .Net' started by user, Apr 26, 2007.

  1. user

    user Guest

    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 ..
     
    user, Apr 26, 2007
    #1
    1. Advertising

  2. user

    Hans Kesting Guest

    > 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
     
    Hans Kesting, Apr 26, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message news:OnvVGI$...
    > 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 ..
     
    Juan T. Llibre, Apr 26, 2007
    #3
  4. user

    Will Guest

    On Apr 26, 12:59 pm, "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 ..


    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.
     
    Will, Apr 26, 2007
    #4
  5. 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 ..
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 26, 2007
    #5
  6. user

    Phil H Guest

    On 26 Apr, 17:26, Peter Bromberg [C# MVP]
    <> 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
     
    Phil H, Apr 26, 2007
    #6
  7. user

    user Guest

    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" <> a écrit dans le message de
    news:OnvVGI$...
    > 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 ..
    >
    >
     
    user, Apr 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    879
    Purvi T
    Oct 19, 2004
  2. mike parr
    Replies:
    1
    Views:
    497
    Marina
    May 20, 2004
  3. Ben Fidge
    Replies:
    5
    Views:
    748
    S. Justin Gengo
    Jun 15, 2004
  4. Amy
    Replies:
    0
    Views:
    1,011
  5. Max2006
    Replies:
    2
    Views:
    1,593
    Walter Wang [MSFT]
    Sep 19, 2007
Loading...

Share This Page