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

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

Reading what the visitor typed

A form is a set of values travelling from the browser to the server. Your job is to read each value safely.

Read each control by name

C#
string name = txtName.Text.Trim();
string chosen = ddlSize.SelectedValue;
bool agreed = chkAgree.Checked;

Handle empty and odd input

  • Trim whitespace so a space is not mistaken for a value.
  • Check for an empty string before using it.
  • Convert numbers with care, because text is not a number.
Never trust the browser. Anyone can send a form value that your page never offered. Treat every value as untrusted until you have checked it, and never build a database query by joining text together.

The tidiest way to check input is a validation control, beginning with making a field required.

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.