Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Reacting to a change in a text box

A text box can notify the server the moment its content changes. The mechanism is a property called auto post back.

How it works

Set the property to true on the control, then handle its changed event. When the visitor edits the box and moves away, the page posts back and your handler runs.

C#
protected void postcodeBox_TextChanged(
    object sender, EventArgs e)
{
    areaLabel.Text = LookUpArea(postcodeBox.Text);
}

When to use it

  • When the next field depends on the value just typed.
  • When a lookup saves the visitor a separate step.

When to avoid it

Every post back is a round trip to the server. On a slow connection that is a visible pause. For an optional convenience, letting the visitor submit a form once is usually kinder.

Test on a slow link. What feels instant on your desk can feel broken on a phone. Watch the page on a throttled connection before you ship it.

Reading the value the visitor typed is covered next in reading what the visitor typed.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.