0

How can I used if (IsPostBack){} to display user's names from two text boxes into another text box?

I have 3 text boxes and a button. The text boxes are named txtLastName, txtGivenName, txtOutput. My button is btnSubmit.

How can I display text from the txtLastName and txtGivenName in the txtOutput text box?

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)
    {
    }
}
Pankaj
  • 9,749
  • 32
  • 139
  • 283
GivenPie
  • 1,451
  • 9
  • 36
  • 57

4 Answers4

2

Create an event handler for the Click event on the button and then in the code behind, do like this:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    txtOutput.Text = string.Format("{0} {1}", txtGivenName.Text, txtLastName.Text);
}
Pankaj
  • 9,749
  • 32
  • 139
  • 283
Rupo
  • 402
  • 3
  • 8
1

How can I display text from the txtLastName and txtGivenName in the txtOutput text box?

  1. Go to the design of your page.
  2. Click the button.
  3. Click F4 or Right click and select properties. This will show you a window for button.
  4. Click the event.
  5. Double click the "Click" action.
  6. This will navigate you to the code behind.
  7. Write the code in this handler
  8. This is how the design will look like for your event handler

enter image description here


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;
Pankaj
  • 9,749
  • 32
  • 139
  • 283
0

try this

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
        txtOutput.Text = txtLastName.Text + " " + txtLastName.Text;
}
Pankaj
  • 9,749
  • 32
  • 139
  • 283
You knows who
  • 885
  • 10
  • 18
0

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;
}
Pankaj
  • 9,749
  • 32
  • 139
  • 283
Chase Florell
  • 46,378
  • 57
  • 186
  • 376