Validation in asp.net

 Simple Validation Example
copy the following in the file with extension .aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server"><div><asp:Label ID="Label1" runat="server" Text="A number (1- 10)">
</asp:Label>
<asp:RangeValidator ID="RangeValidator1" runat="server"ErrorMessage="This Number Is Not In The Range&quot;" ControlToValidate="TextBox1" MaximumValue="10" MinimumValue="1" Type="Integer">*</asp:RangeValidator>
<asp:TextBox ID="TextBox1"runat="server"></asp:TextBox><br /><br />
<asp:Label ID="Label2" runat="server" Text="A number"></asp:Label><asp:TextBoxID="TextBox2" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button_submit" runat="server"Text="submit" onclick="Button_submit_Click" /><br /><br /><asp:Label ID="Label3" runat="server"></asp:Label><br />
</div>
</form></

body></

html>


Copy the following code in file with extension .aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Validationsimple_Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){

}

protected void Button_submit_Click(object sender, EventArgs e){

Label3.Text ="cmdOK_Click event handler executed.";}

}

No comments:

Post a Comment