3

I'm trying to get client-side validation running. I've put together a very simple test - file name is aTET3.aspx:

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

<!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>TEST</title>

    <script type="text/javascript">
    //<![CDATA[
    function TEST() 
    {
        alert("INSIDE TEST");
        alert("ValidatorCommonOnSubmit()=" + ValidatorCommonOnSubmit());
        alert("Page_ClientValidate()=" + Page_ClientValidate());
    }
    //]]>
    </script>
</head>

<body link="#1A548E" vlink="#1A548E" alink="#1A548E" onunload="TEST()">

<form name="appForm" method="post" action="aTET3.aspx" id="appForm" runat="server">
<asp:ValidationSummary id="appValidationSummary" 
    ValidationGroup="appValidation" 
    DisplayMode="List"
    EnableClientScript="true"
    HeaderText="Loan application not ready"
    runat="server"
    Enabled="true"
    Visible="true" 
    ShowSummary="true" />
<asp:Label ID="lblMessage" Font-Bold="true" ForeColor="Red" runat="server" />

<br />
Enter amount:

<asp:RequiredFieldValidator ID="ApplicationAmountValidator" 
    ValidationGroup="appValidation" 
    ControlToValidate="txtApplicationAmount"
    ErrorMessage="Application amount is required." 
    EnableClientScript="true" 
    Enable="true"
    Display="Dynamic"
    runat="server">+++</asp:RequiredFieldValidator>

<asp:TextBox ID="txtApplicationAmount" Columns="6" runat="server" />

<br /><br />

<asp:Button ID="btnSave" runat="server" Text="Send Application" 
     CausesValidation="true" />

</form>


</body>
</html>

The page has a single textbox with a RequiredFieldValidator. There is also a ValidationSummary control, and a submit button. (I added the TEST() method, called on Unload, to check the state of the page just before callback.) No client-side validation occurs; instead, the request is sent back to the server. If I call Validate() on the server, then I get validation.

I have tried adding ValidateRequest="true" to the Page directive with same results.

When I look at the emitted JavaScript, a few things jump out to me. Here's part of it:

<script type="text/javascript">
<!--
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
    ValidatorOnLoad();
}

function ValidatorOnSubmit() {
    if (Page_ValidationActive) {
        return ValidatorCommonOnSubmit();
    }
    else {
        return true;
    }
}
// -->
</script>

Note that Page_ValidationActive is set to False, which means that ValidatorOnSubmit always returns true. That seems odd to me, except that I looked at 'WebUIValidation.js', and see that ValidatorCommonOnSubmit does not validate the page anyhow - the Page_ClientValidate() method does, but how do I get it to run?

In my TEST() method, when I manually call Page_ClientValidate(), the form does get validated client-side as expected - and the postback request is sent back to the server.

I've tested with both Firefox 3.0.10 and Internet Explorer 7, with same results.

What am I missing?

1 Answer 1

2

You have to have all the validation stuff in the same validation group. Including the button that fires the validation.

Sign up to request clarification or add additional context in comments.

1 Comment

I've had this problem before with this resolution but this time the issue persisted after including the validation group everywhere. In the end I needed to set xhtml conformance correctly in my web.config <xhtmlConformance mode="Transitional" /> See: stackoverflow.com/questions/422554/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.