I am new to ASP.Net and would like some help with a simple scenario:
我是ASP.Net的新手,想要一个简单场景的帮助:
Currently in my web application I have one button and one textbox in my web application. When I click the button I want to display a result in the text box.
目前在我的Web应用程序中,我的Web应用程序中有一个按钮和一个文本框。当我单击按钮时,我想在文本框中显示结果。
How should I do this?
我该怎么做?
6 个解决方案
#1
7
If you're using ASP.NET WebForms you can add a Click event handler to the button to set the text box's text:
如果您使用的是ASP.NET WebForms,则可以向该按钮添加Click事件处理程序以设置文本框的文本:
protected void Button1_Click(object sender, EventArgs e)
{
MyTextBox.Text = "Text to display";
}
You can either use autowireup to get the event handler wired to the button, or explicitly assign the event handler to the event in the Page_Load() method.
您可以使用autowireup将事件处理程序连接到按钮,或者在Page_Load()方法中将事件处理程序显式分配给事件。
The easiest way to assign the event to the button is to declare it in the .aspx code like this:
将事件分配给按钮的最简单方法是在.aspx代码中声明它,如下所示:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
It will be done automatically if you doubleclick this button in the designer mode.
如果在设计器模式下双击此按钮,它将自动完成。
#2
3
You can set the result in a button Click Handler like...
您可以在按钮中设置结果单击处理程序,如...
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Result Text.....";
}
There is a Text
property of Textbox controls, that is used to Set/Get
values.
Textbox控件有一个Text属性,用于设置/获取值。
#3
2
public void button_Click(object sender, CommandEventArgs e)
{
txt.Text = "Testing";
}
#4
2
lambdas anyone???
button.Click += (s, e) => { textbox.Text = "whoa!"; }
hmmm?
#5
1
public void button_Click(object sender, EventArgs e)
{
string str="String";
int i=100;
textbox1.Text = "string text";
//or
textbox1.Text = str;
//or
textbox1.Text = i.Tostring();
//and same as above for other types i.e, convert to string when assigning to textBox because textbox takes value as string only
}
#6
0
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Text Message";
}
Refer this link to get started: http://www.knowdotnet.com/
请参阅此链接以开始使用:http://www.knowdotnet.com/
For submit button properties check this: MSDN Button Control
对于提交按钮属性,请检查:MSDN按钮控件
#1
7
If you're using ASP.NET WebForms you can add a Click event handler to the button to set the text box's text:
如果您使用的是ASP.NET WebForms,则可以向该按钮添加Click事件处理程序以设置文本框的文本:
protected void Button1_Click(object sender, EventArgs e)
{
MyTextBox.Text = "Text to display";
}
You can either use autowireup to get the event handler wired to the button, or explicitly assign the event handler to the event in the Page_Load() method.
您可以使用autowireup将事件处理程序连接到按钮,或者在Page_Load()方法中将事件处理程序显式分配给事件。
The easiest way to assign the event to the button is to declare it in the .aspx code like this:
将事件分配给按钮的最简单方法是在.aspx代码中声明它,如下所示:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
It will be done automatically if you doubleclick this button in the designer mode.
如果在设计器模式下双击此按钮,它将自动完成。
#2
3
You can set the result in a button Click Handler like...
您可以在按钮中设置结果单击处理程序,如...
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Result Text.....";
}
There is a Text
property of Textbox controls, that is used to Set/Get
values.
Textbox控件有一个Text属性,用于设置/获取值。
#3
2
public void button_Click(object sender, CommandEventArgs e)
{
txt.Text = "Testing";
}
#4
2
lambdas anyone???
button.Click += (s, e) => { textbox.Text = "whoa!"; }
hmmm?
#5
1
public void button_Click(object sender, EventArgs e)
{
string str="String";
int i=100;
textbox1.Text = "string text";
//or
textbox1.Text = str;
//or
textbox1.Text = i.Tostring();
//and same as above for other types i.e, convert to string when assigning to textBox because textbox takes value as string only
}
#6
0
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Text Message";
}
Refer this link to get started: http://www.knowdotnet.com/
请参阅此链接以开始使用:http://www.knowdotnet.com/
For submit button properties check this: MSDN Button Control
对于提交按钮属性,请检查:MSDN按钮控件