Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a some problem..

in a aspx form have a textbox ans three buttons. on clicking each button textbox display different text. and all buttons click event call same function in aspx.cs file.

how do it.. plse help me..
Posted

If you are calling a same function then you have to pass one parameter to indicate which button_click event calling that function.
that only i can suggest from your question
 
Share this answer
 
Comments
SKDeveloper 24-Sep-12 6:17am    
in this condition we use only button click event method [protected void Button1_Click(object sender, EventArgs e){ }] in all button click event.. how do this..
Then what is the problem? You can check with the ID of the button.
Try this:
C#
protected void buttonGroup_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    if(btn.ID == "Button1")
          TextBox1.Text = "Button1 clicked";
    else if(btn.ID == "Button2")
          TextBox1.Text = "Button2 clicked";
    else if(btn.ID == "Button3")
          TextBox1.Text = "Button3 clicked";
}



Hope it helps.!
--Amit
 
Share this answer
 
Comments
SKDeveloper 24-Sep-12 6:30am    
this is good... but..
this question ask me in a interview.. i give same ans.. interviewer said this also done .net 2.0, but how will do in .net 4.0..??
_Amy 24-Sep-12 6:34am    
There is many ways, using button text, button command and many more things. But you should check it in Stupid questions asked in interviews[^].
C#
protected void buttonGroup_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    if(btn.ID == "Button1")
          TextBox1.Text = "Button1 clicked";
    else if(btn.ID == "Button2")
          TextBox1.Text = "Button2 clicked";
    else if(btn.ID == "Button3")
          TextBox1.Text = "Button3 clicked";
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900