One button to know which button got clicked?

Discussion in 'ASP .Net' started by bthumber, May 21, 2010.

  1. bthumber

    bthumber Guest

    I have two buttons on a messaging form. A "To" (who's going to get the
    message) and "Cc" (who's going to get a copy). The user choose the names from
    a listbox that popup when the "To" button is clicked. When the user click the
    "Ok" button the name is moved to the "To" label.

    If the user now wishes to CC someone how do I get the "ok" button to know
    I've click the "CC" and not the "To" and to put the name on the "CC" label?

    I tried switch statement but was not working

    view plaincopy to clipboardprint?
    string text = btnTo.text;
    switch (text.trim())
    {
    case "To":
    Do something
    break;
    case "Cc":
    Do something
    break;
    default:
    Label1 += "Please choose To.";
    }

    string text = btnTo.text;
    switch (text.trim())
    {
    case "To":
    Do something
    break;
    case "Cc":
    Do something
    break;
    default:
    Label1 += "Please choose To.";
    } view plaincopy to clipboardprint?


    view plaincopy to clipboardprint?
    Do know how to get one button to know which choice I maded To or Cc, To and
    Cc

    Do know how to get one button to know which choice I maded To or Cc, To and Cc
    bthumber, May 21, 2010
    #1
    1. Advertising

  2. On May 21, 7:24 pm, bthumber <>
    wrote:
    > I have two buttons on a messaging form. A "To" (who's going to get the
    > message) and "Cc" (who's going to get a copy). The user choose the names from
    > a listbox that popup when the "To" button is clicked. When the user click the
    > "Ok" button the name is moved to the "To" label.
    >
    > If the user now wishes to CC someone how do I get the "ok" button to know
    > I've click the "CC" and not the "To" and to put the name on the "CC" label?
    >
    > I tried switch statement but was not working
    >
    > view plaincopy to clipboardprint?
    > string text = btnTo.text;      
    > switch (text.trim())      
    > {      
    >    case "To":      
    >       Do something      
    >       break;      
    >    case "Cc":      
    >       Do something      
    >       break;      
    >    default:      
    >       Label1 += "Please choose To.";      
    >
    > }    
    >
    > string text = btnTo.text;  
    > switch (text.trim())  
    > {  
    >    case "To":  
    >       Do something  
    >       break;  
    >    case "Cc":  
    >       Do something  
    >       break;  
    >    default:  
    >       Label1 += "Please choose To.";  
    >
    > }  view plaincopy to clipboardprint?
    >
    >  view plaincopy to clipboardprint?
    > Do know how to get one button to know which choice I maded To or Cc, To and
    > Cc  
    >
    > Do know how to get one button to know which choice I maded To or Cc, To and Cc


    http://www.aspdotnetfaq.com/Faq/How-to-determine-which-Control-caused-PostBack-on-ASP-NET-page.aspx
    Alexey Smirnov, May 21, 2010
    #2
    1. Advertising

  3. "bthumber" <> wrote in message
    news:...

    > Do know how to get one button to know which choice I maded To or Cc, To
    > and Cc


    Although Alexey's suggestion will work, its usage is not encouraged. A much
    better method (IMO) is to use CommandButtons rather than ordinary Buttons
    and specify their CommandName and/or CommandArgument properties.
    CommandButtons were designed precisely for this sort of scenario.

    So, you create three buttons, set their OnClick property to the same
    server-side method, but specify different CommandName properties for each
    button:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandname.aspx


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], May 22, 2010
    #3
  4. On May 22, 1:27 pm, "Mark Rae [MVP]" <> wrote:
    > "bthumber" <> wrote in message
    >
    > news:...
    >
    > > Do know how to get one button to know which choice I maded To or Cc, To
    > > and Cc

    >
    > Although Alexey's suggestion will work, its usage is not encouraged. A much
    > better method (IMO) is to use CommandButtons rather than ordinary Buttons
    > and specify their CommandName and/or CommandArgument properties.
    > CommandButtons were designed precisely for this sort of scenario.
    >
    > So, you create three buttons, set their OnClick property to the same
    > server-side method, but specify different CommandName properties for each
    > button:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.but...
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    Yes, I agree, it makes sense
    Alexey Smirnov, May 25, 2010
    #4
  5. bthumber

    bthumber Guest

    Thanks!

    "Mark Rae [MVP]" wrote:

    > "bthumber" <> wrote in message
    > news:...
    >
    > > Do know how to get one button to know which choice I maded To or Cc, To
    > > and Cc

    >
    > Although Alexey's suggestion will work, its usage is not encouraged. A much
    > better method (IMO) is to use CommandButtons rather than ordinary Buttons
    > and specify their CommandName and/or CommandArgument properties.
    > CommandButtons were designed precisely for this sort of scenario.
    >
    > So, you create three buttons, set their OnClick property to the same
    > server-side method, but specify different CommandName properties for each
    > button:
    > http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandname.aspx
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    bthumber, Jun 25, 2010
    #5
    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. =?Utf-8?B?R2Vvcmdl?=

    How to know which LinkButton clicked?

    =?Utf-8?B?R2Vvcmdl?=, Apr 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,748
    =?Utf-8?B?R2Vvcmdl?=
    Apr 6, 2004
  2. Bob
    Replies:
    3
    Views:
    1,399
  3. Yossi

    Which button was clicked and on which row?

    Yossi, Nov 17, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    730
    Yossi
    Nov 17, 2006
  4. Jim Mitchell
    Replies:
    0
    Views:
    190
    Jim Mitchell
    Jul 12, 2003
  5. Replies:
    6
    Views:
    109
Loading...

Share This Page