One button to know which button got clicked?

B

bthumber

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
 
G

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

http://www.aspdotnetfaq.com/Faq/How-to-determine-which-Control-caused-PostBack-on-ASP-NET-page.aspx
 
M

Mark Rae [MVP]

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
 
G

Guest

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...

Yes, I agree, it makes sense
 
B

bthumber

Thanks!

Mark Rae said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top