[英]How do you use if (IsPostBack) in ASP.NET C#
How can I used if (IsPostBack){}
to display user's names from two text boxes into another text box? 如何使用if (IsPostBack){}
将用户名从两个文本框中显示到另一个文本框中?
I have 3 text boxes and a button. 我有3个文本框和一个按钮。 The text boxes are named txtLastName, txtGivenName, txtOutput. 这些文本框被命名为txtLastName,txtGivenName,txtOutput。 My button is btnSubmit. 我的按钮是btnSubmit。
How can I display text from the txtLastName and txtGivenName in the txtOutput text box? 如何显示txtOutput文本框中的txtLastName和txtGivenName中的文本?
How can I display it as: First (space) Lastname or Last, Firstname in this code. 如何将其显示为:此代码中的名字(空格)姓氏或姓氏,名字。
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
}
}
Create an event handler for the Click event on the button and then in the code behind, do like this: 在按钮上为Click事件创建一个事件处理程序,然后在后面的代码中,如下所示:
protected void btnSubmit_Click(object sender, EventArgs e)
{
txtOutput.Text = string.Format("{0} {1}", txtGivenName.Text, txtLastName.Text);
}
How can I display text from the txtLastName and txtGivenName in the txtOutput text box? 如何显示txtOutput文本框中的txtLastName和txtGivenName中的文本?
protected void btnSubmit_Click(object sender, EventArgs e)
{
txtOutput.Text = string.Format("{0} {1}", txtGivenName.Text, txtLastName.Text);
}
How can I display it as: First (space) Lastname or Last, Firstname in this code. 如何将其显示为:此代码中的名字(空格)姓氏或姓氏,名字。
Write down the code in the handler as below. 如下所示在处理程序中写下代码。
txtOutput.Text = txtLast.Text + ", " + txtFirst.Text;
try this 尝试这个
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
txtOutput.Text = txtLastName.Text + " " + txtLastName.Text;
}
Why don't use use the submit button method to achieve this? 为什么不使用提交按钮方法来实现此目的?
protected void btnSubmit_Click(object sender, System.EventArgs e)
{
txtOutput.Text = txtLast.Text + ", " + txtFirst.Text;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.