File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ManualValidation" %>
Manual Validation
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ManualValidation : System.Web.UI.Page
{
protected void cmdOK_Click(object sender, EventArgs e)
{
string errorMessage = "Mistakes found:
";
bool pageIsValid = true;
foreach (BaseValidator ctrl in this.Validators)
{
if (!ctrl.IsValid)
{
pageIsValid = false;
errorMessage += ctrl.ErrorMessage + "
";
TextBox ctrlInput = (TextBox)this.FindControl(ctrl.ControlToValidate);
errorMessage += " * Failed: ";
errorMessage += ctrlInput.Text + "
";
}
}
if (!pageIsValid) lblMessage.Text = errorMessage;
}
}