File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RegularExpressionTest" %>
<!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>Regular Expression Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="txtExpression"
runat="server"
Width="192px"></asp:textbox>
<asp:button id="cmdSetExpression"
runat="server"
Width="138px"
Text="Set This Expression"
CausesValidation="False"
OnClick="cmdSetExpression_Click">
</asp:button>
<asp:label id="lblExpression"
runat="server"
Height="21px"
Width="512px" >Current Expression: (none)</asp:label>
<asp:label id="Label1"
runat="server" >New Expression:</asp:label>
<div>
<asp:validationsummary id="ValidationSummary1" runat="server" ></asp:validationsummary>
<asp:regularexpressionvalidator id="TestValidator"
runat="server"
EnableClientScript="False"
ErrorMessage="Failed Validation"
ControlToValidate="txtValidate"></asp:regularexpressionvalidator>
<asp:textbox id="txtValidate" runat="server" Width="192px"></asp:textbox>
<asp:button id="cmdValidate" runat="server" Width="139px" Text="Validate"></asp:button>
<asp:label id="Label2" runat="server" Height="16px" Width="184px" >Test Current Expression:</asp:label>
</div>
</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 RegularExpressionTest : System.Web.UI.Page
{
protected void cmdSetExpression_Click(object sender, EventArgs e)
{
TestValidator.ValidationExpression = txtExpression.Text;
lblExpression.Text = "Current Expression: ";
lblExpression.Text += txtExpression.Text;
}
}
|