How to load 3rd range validator after tabout of textbox1 and 2.

kravindra
kravindra used Ask the Experts™
on
Hi,

I have 3 textboxs and 3 Range validators.
3rd textbox is readonly.
Values in 3rd text box is sum of first two textbox,this code i writen in javascript.
3rd range validator is firing after button click only.
I need it to fire after tabout of textbox1 or textbox2.
COuld you please help me,is there any solution for it.

<%@ 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">

<?xml version="1.0" encoding="iso-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml2rtf="http://www.lutecia.info/download/xmlns/xhtml2rtf">
  <head id="Head1" runat="server">
    <title></title>
    <script language="javascript">
        function xyz() {
            document.getElementById("TextBox3").value = document.getElementById("TextBox1").value + document.getElementById("TextBox2").value;
            }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator2" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0" SetFocusOnError="True"></asp:RangeValidator>
        <br />
        <asp:TextBox onblur="xyz();" ID="TextBox2" runat="server"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator3" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0" SetFocusOnError="True"></asp:RangeValidator>
        <br />
    <asp:TextBox ID="TextBox3" ReadOnly="true" runat="server" ValidationGroup="abcd"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator1" runat="server"
            ControlToValidate="TextBox3" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0"></asp:RangeValidator>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button"/> </div>
   &nbsp;</div></form>
</body>
</html>
</xml>


thanks in Advance

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
use clientside validation like this: see the attached code...

if (Page_ClientValidate() == false) {
                document.getElementById("RangeValidator1").visibility = true;
            }

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

<html>

  <head id="Head1" runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function xyz() {
            document.getElementById("TextBox3").value = document.getElementById("TextBox1").value + document.getElementById("TextBox2").value;
            if (Page_ClientValidate() == false) {
                document.getElementById("RangeValidator1").visibility = true;
            }
            }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator2" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0" SetFocusOnError="True"></asp:RangeValidator>
        <br />
        <asp:TextBox onblur="xyz();" ID="TextBox2" runat="server"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator3" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0" SetFocusOnError="True" ></asp:RangeValidator>
        <br />
    <asp:TextBox ID="TextBox3" ReadOnly="true" runat="server" ></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator1" runat="server"
            ControlToValidate="TextBox3" ErrorMessage="RangeValidator" MaximumValue="10"
            MinimumValue="0"></asp:RangeValidator>
        <br />
        <asp:Button ID="Button1" ValidationGroup="abcd" runat="server" Text="Button"/> </div>
   &nbsp;</div></form>
</body>
</html>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial