Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

RequiredFieldValidator Class - ASP.NET

RSS
Modified on Tue, Sep 15, 2009, 11:54 AM by Administrator Categorized as ASP·NET Web Forms, Class Library
This page is part of the Class Library Pages collection.
Click the icon to see the index.

Features

Provides standardized required-field validation across a website.

Sample Implementation

To use this control, you need to follow the instructions in the Consuming Custom Controls in ASP.NET article.

ASPX Markup

<abc:RequiredFieldValidator runat="server" 
    ControlToValidate="uxFirstNameTextBox" 
    Entity="First Name" 
    ValidationGroup="MainValidationGroup"
    />

Source Code

VB.NET

Imports Microsoft.VisualBasic
Imports System.Web.UI.WebControls

Namespace AcmeBroomCompany

    Public Class RequiredFieldValidator

        Inherits System.Web.UI.WebControls.RequiredFieldValidator

        Private _entity As String

        Public Sub New()

            Display = ValidatorDisplay.Dynamic
            EnableClientScript = True
            SetFocusOnError = True
            Text = ""

            Dim img As Image = New Image()
            img.ImageUrl = "~/images/Exclamation.png"
            Me.Controls.Add(img)

            _entity = ""

        End Sub

        Public Property Entity() As String
            Get
                Return _entity
            End Get
            Set(ByVal value As String)
                _entity = value
                ErrorMessage = _entity & " must be specified."
            End Set
        End Property

    End Class

End Namespace

C#

TODO

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.