Aik*_*iko 4 c# asp.net textbox button
我有几个按钮和一个文本框.我想这样做,当我按下按钮1时,文本框中的文本转到按钮,当我按下按钮2时,文本转到按钮2,依此类推.我现在有这个:
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = TextBox1.Text;
}
protected void Button2_Click(object sender, EventArgs e)
{
Button2.Text = TextBox1.Text;
}
protected void Button3_Click(object sender, EventArgs e)
{
Button3.Text = TextBox1.Text;
}
Run Code Online (Sandbox Code Playgroud)
编辑:有没有更短的方法来做到这一点?
如果您将Click每个按钮的事件指向同一个方法,您可以在一个方法中使用它;
protected void Button_Click(object sender, EventArgs e)
{
((Button)sender).Text = TextBox1.Text;
}
Run Code Online (Sandbox Code Playgroud)
您可以通过单击按钮,转到"属性"窗口并单击事件的小闪电符号并选择事件的方法来更改设计器中用于按钮事件的Button_Click方法Click.