Set Minimum/Maximum Value, ErrorMessage, ControlToValidate, EnableClientScript for asp:RangeValidator (C#) : RangeValidator « Validation « ASP.NET Tutorial






File: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ValidationTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Validation Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    A number (1 to 10):
    <asp:TextBox id="txtValidated" runat="server"></asp:TextBox>
    <asp:RangeValidator id="RangeValidator" 
                        runat="server" 
                        ErrorMessage="This Number Is Not In The Range" 
                        ControlToValidate="txtValidated" 
                        MaximumValue="10" 
                        MinimumValue="1" 
                        Type="Integer" 
                        EnableClientScript="False"></asp:RangeValidator>&nbsp;
    Not validated:
    <asp:TextBox id="txtNotValidated" runat="server"></asp:TextBox><br />
  
   <asp:Button id="cmdOK" 
                runat="server" 
                Text="OK" 
                OnClick="cmdOK_Click" 
                Width="46px"></asp:Button><br />
    <asp:Label id="lblMessage" 
               runat="server" 
               EnableViewState="False" 
               Font-Bold="True" 
               ForeColor="Red"></asp:Label>&nbsp;
  
    </div>
    </form>
</body>
</html>


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 ValidationTest : System.Web.UI.Page
{
  protected void cmdOK_Click(object sender, EventArgs e)
  {
    if (!Page.IsValid) return;
    lblMessage.Text = "cmdOK_Click event handler executed.";
  }
}








8.8.RangeValidator
8.8.1.RangeValidator checks whether the value falls between a minimum and maximum value
8.8.2.Set Minimum/Maximum Value, ErrorMessage, ControlToValidate, EnableClientScript for asp:RangeValidator (C#)
8.8.3.Manual Validation
8.8.4.Use asp:RangeValidator to check the value range in an asp:textbox
8.8.5.asp:RangeValidator is converted to JavaScript code after loading in client side
8.8.6.Using the RangeValidator control to test an integer value
8.8.7.Using the RangeValidator control to test a string date value (C#)
8.8.8.Using the RangeValidator control to test a string date value (VB.net)
8.8.9.RangeValidator for number and date
8.8.10.Birthday range