CustomValidator doesn;t work

G

Guest

wroten following aspx in VWD 2005

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1"
EnableClientScript="False" ErrorMessage="error!"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator><br
/>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" /></div>
</form>
</body>
</html>

code behind .cs
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Response.Write("Valid");
}
else
Response.Write("InValid");
}
}


Even the args.isValid always set to "false", Valid is printed you to the page.
I set a breakpoint in "agrs.isValid = false", but the program doesn;t stop
in the line when I click the button, the Server Validation haven't run.

Tried similar code in v1.1 VS2003, but still failed. Does I missed something?

Thanks for help

Jason Chan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top