Validation Controls, Login Control; Master Pages, CSS & Themes

Four features that make a Web Forms app polished and safe: validation controls that check user input, a ready-made Login control, master pages that give every page one shared layout, and themes with CSS for consistent styling.

11 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Polished, safe, and consistent

A working registration form is not enough. FestConnect also needs to reject bad input (an empty name, a malformed email), let students log in, look the same on every page, and be easy to restyle. ASP.NET Web Forms has a ready-made feature for each of these.

This lesson groups four of them: validation controls (check input), the Login control (sign-in UI), master pages (one shared layout), and themes with CSS (consistent styling). Each saves you from writing a lot of repetitive code by hand.

Theory

Validation controls

Validation controls check a user's input and block the form from submitting until it is correct, showing an error message if not. You attach one to the control it should check. The common ones:

  • RequiredFieldValidator: the field must not be empty.
  • RangeValidator: the value must fall within a range (for example age 16 to 60).
  • RegularExpressionValidator: the value must match a pattern (for example a valid email).
  • CompareValidator: compare two values (for example 'password' equals 'confirm password').
  • ValidationSummary: gather and list all the errors in one place.

They check in the browser for speed, and ASP.NET re-checks on the server for safety.

Practical

Requiring a name on the FestConnect form

<asp:TextBox id="txtName" runat="server" />

<asp:RequiredFieldValidator
    runat="server"
    ControlToValidate="txtName"
    ErrorMessage="Please enter your name"
    ForeColor="Red" />

<asp:Button id="btnRegister" Text="Register" runat="server" />
<!-- The button will not post back until txtName is filled in. -->

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Theory

Login control, master pages, themes

The Login control is a ready-made sign-in box (username, password, a Login button) that plugs into ASP.NET's membership system, so you get a working login without building the UI yourself.

A master page defines the shared layout of the site, the header, menu and footer, once, with a ContentPlaceHolder marking the region that changes. Each content page (Register, Events, Profile) supplies only its own content to fill that placeholder. Write the layout once; every page inherits it.

Themes and CSS handle the look: a theme is a site-wide bundle of styles (and control skins), so you set colours and fonts in one place and the whole app stays consistent.

Formula

Why these four belong together

Each of these removes hand-written repetition and centralises a concern. Validation centralises 'is this input acceptable'. The Login control centralises signing in. Master pages centralise the layout. Themes and CSS centralise the styling.

The pattern is the same one you saw with code-behind: define a thing ONCE, in the right place, and reuse it everywhere, instead of copying it onto every page and maintaining dozens of drifting copies.

At a glance

FeatureJobDefined once, used everywhere?
Validation controlsCheck user input, block bad dataAttached per field, reused across forms
Login controlReady-made sign-in UIDrop in wherever login is needed
Master pagesOne shared page layoutYes: layout written once, all pages inherit
Themes + CSSConsistent site-wide stylingYes: styles set once, applied everywhere

Quiz

You need the FestConnect email field to accept only properly formatted email addresses. Which validation control fits?

  1. RequiredFieldValidator, because it checks the format of the text
  2. RegularExpressionValidator, because it checks the value against a pattern such as an email format
  3. CompareValidator, because it compares the email to a pattern
  4. RangeValidator, because an email is a range of characters
Show the answer

RegularExpressionValidator, because it checks the value against a pattern such as an email format

RegularExpressionValidator checks a value against a PATTERN (a regular expression), which is exactly how you validate an email's format. Option A is wrong: RequiredFieldValidator only checks that the field is not empty, not its format, an empty check and a format check are different jobs (you often use both). Option C is wrong: CompareValidator compares two values (like password and confirm-password) or a value to a fixed constant, not to a pattern. Option D is wrong: RangeValidator checks that a value lies between a minimum and maximum (useful for numbers or dates), not that text matches a format. Match the validator to the kind of check: pattern -> RegularExpressionValidator.

Think first

Why use a master page instead of copying the layout onto each page?

You could just paste the same header, menu and footer into every .aspx. Why is a master page better? Then tap.

Show the answer

Because a master page defines the shared layout in ONE place, so a change is made once and appears everywhere, while copy-pasted layout must be edited on every page and inevitably drifts out of sync. Imagine FestConnect has 20 pages, each with the same header and menu pasted in. Add one menu item, 'Results', and you must edit all 20 files identically; miss one, or make a typo, and that page is now inconsistent. With a master page, the header and menu live in the master, and every content page fills only its ContentPlaceHolder, so adding the menu item is a single edit that instantly updates all 20 pages. Same reasoning as separating layout from logic, or centralising styles in CSS: define once, reuse everywhere, maintain in one spot. It is less work now and far less work later. One source of truth beats twenty copies.

Summary

Key takeaways

  • Validation controls check user input and block submission until it is correct: RequiredFieldValidator (not empty), RangeValidator (within range), RegularExpressionValidator (matches a pattern), CompareValidator (compare two values), ValidationSummary (list errors).
  • Validation runs in the browser for speed and is re-checked on the server for safety.
  • The Login control is a ready-made sign-in UI that plugs into ASP.NET membership.
  • A master page defines the shared layout once (header, menu, footer) with a ContentPlaceHolder; content pages fill in only their part.
  • Themes and CSS centralise styling so the whole site stays consistent from one place.
  • The common thread: define a concern once, in the right place, and reuse it everywhere.
  • Memory hook: validate input, log in, lay out once (master page), style once (theme).

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to ASP.NET

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Validation Controls, Login Control; Master Pages, CSS & Themes · .NET Technology (Major-13) · Gri-Learn