|
ValidatorEventHandler delegateFull pathMadWidgets.Validation.ValidatorEventHandler
Declarationpublic delegate ValidatorEventHandler(Validator v);
OverviewThe ValidatorEventHandler delegate is used to reference a method that will handle an event generated by the Validator control. Currently both the PreValidate event and the PostValidate event use this delegate.The following example shows how this is done with these two events: <%@ Control Language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="MadWidgets.Validation" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<script runat="server">
void Page_Load(object o, EventArgs ea)
{
Validator v = Validator.Current;
v.Add(new ValidatorEntryRegex(Username, "You have not supplied a valid username.", null, true, false, "^[a-z][a-z0-9-_.]{4,19}$", RegexOptions.IgnoreCase));
v.Add(new ValidatorEntryRegex(Password, "You have not supplied a valid password.", null, true, false, "^[a-z][a-z0-9-_.]{4,19}$", RegexOptions.IgnoreCase));
if (v.IsPostBack)
{
v.PreValidate += new ValidatorEventHandler(HandlePreValidate);
v.PostValidate += new ValidatorEventHandler(HandlePostValidate);
}
}
void Submit_Clicked(object o, EventArgs ea)
{
if (Page.IsValid)
{
// Do your thang here!
SuccessMessage.Text = "That's great! You just logged in!";
}
}
void HandlePreValidate(Validator v)
{
// Do whatever needs to be done prior to validation
}
void HandlePostValidate(Validator v)
{
// Do whatever needs to be after validation
}
</script>
<asp:Literal id="SuccessMessage" runat="server" />
<div class="demoBlock">
<b>Login</b><br />
<div class="formLabel">Username</div>
<div class="formInput"><input type="text" id="Username" size="35" runat="server" /></div>
<div class="formLabel">Password</div>
<div class="formInput"><input type="password" id="Password" size="35" runat="server" /></div>
<div class="formButtonBar">
<input type="submit" id="Login" value="Login" class="formButton" onserverclick="Submit_Clicked" runat="server" />
</div>
</div> © 2002 - 2009 Copyright, Disclaimer and Privacy Statement |
||||||