OK button doesn't work properly with multiple validator controls

Discussion in 'ASP .Net Web Controls' started by Sally, Oct 18, 2005.

  1. Sally

    Sally Guest

    I've created an ASPX page with 2 textboxes and an OK button. The 2
    textboxes each have 2 validator controls, a RequiredFieldValidator and
    a CustomValidator. Both CustomValidator controls link to JavaScript
    validate methods at the top of the ASPX file (HTML view).

    With only 1 textbox and its pair of validator controls, the OK button
    works properly (it displays a status message in a label).

    However, with the 2 sets of textboxes and associated validator
    controls, the OK button no longer works. No postback occurs when you
    click on it.


    The full text of my ASPX file is as follows:

    <%@ Page language="c#" Codebehind="Test.aspx.cs"
    AutoEventWireup="false" Inherits="RecorderLight.Test" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Test</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    <script language="javascript">
    function ValidateEmail(source, arguments)
    {
    if (arguments.Value == "")
    {
    arguments.IsValid = true;
    }
    else
    {
    arguments.IsValid = false;
    }
    }

    function ValidateUsername(source, arguments)
    {
    if (arguments.Value == "sally.revell")
    {
    arguments.IsValid = true;
    }
    else
    {
    arguments.IsValid = false;
    }
    }
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <table style="WIDTH: 632px; HEIGHT: 208px" borderColor="black"
    border="1">
    <tr height="20%">
    <td align="center" colSpan="3">Table Title</td>
    </tr>
    </TR>
    <tr height="40%">
    <td width="20%"><asp:label id="lblEmail"
    runat="server">Email:</asp:label></td>
    <td width="40%"><asp:textbox id="txtEmail"
    runat="server"></asp:textbox></td>
    <td width="40%"><asp:requiredfieldvalidator
    id="RequiredFieldValidator1" runat="server" ErrorMessage="*"
    ControlToValidate="txtEmail"
    EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    id="CustomValidator1" runat="server" ErrorMessage="Email must be
    unique" ControlToValidate="txtEmail"
    ClientValidationFunction="ValidateEmail"
    Display="Dynamic"></asp:customvalidator></td>
    </tr>
    <tr height="40%">
    <td width="20%"><asp:label id="lblUsername"
    runat="server">Username:</asp:label></td>
    <td width="40%"><asp:textbox id="txtUsername"
    runat="server"></asp:textbox></td>
    <td width="40%"><asp:requiredfieldvalidator
    id="RequiredFieldValidator2" runat="server" ErrorMessage="*"
    ControlToValidate="txtUsername"
    EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    id="CustomValidator2" runat="server" ErrorMessage="Username must be
    unique" ControlToValidate="txtUsername"
    ClientValidationFunction="ValidateUsername"
    Display="Dynamic"></asp:customvalidator></td>
    </tr>
    <tr height="40%">
    <td align="center" colSpan="3"><asp:imagebutton id="ImageButton1"
    runat="server" ImageUrl="images/Ok.gif"></asp:imagebutton></td>
    </tr>
    </table>
    <asp:label id="lblStatus" style="Z-INDEX: 101; LEFT: 16px; POSITION:
    absolute; TOP: 240px"
    runat="server" Width="392px"></asp:label></form>
    </body>
    </HTML>


    And here is button click event handler from the C# code behind file:

    private void ImageButton1_Click(object sender,
    System.Web.UI.ImageClickEventArgs e)
    {
    if (Page.IsValid == true)
    {
    lblStatus.Text = "Page is Valid!";
    }
    else
    {
    lblStatus.Text = "Some of the required fields are empty";
    }
    }


    Has anyone else come across this, and, if so, do you know a fix?
    Thanks very much!
     
    Sally, Oct 18, 2005
    #1
    1. Advertising

  2. Sally

    Sally Guest

    Sally wrote:
    > I've created an ASPX page with 2 textboxes and an OK button. The 2
    > textboxes each have 2 validator controls, a RequiredFieldValidator and
    > a CustomValidator. Both CustomValidator controls link to JavaScript
    > validate methods at the top of the ASPX file (HTML view).
    >
    > With only 1 textbox and its pair of validator controls, the OK button
    > works properly (it displays a status message in a label).
    >
    > However, with the 2 sets of textboxes and associated validator
    > controls, the OK button no longer works. No postback occurs when you
    > click on it.
    >
    >
    > The full text of my ASPX file is as follows:
    >
    > <%@ Page language="c#" Codebehind="Test.aspx.cs"
    > AutoEventWireup="false" Inherits="RecorderLight.Test" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>Test</title>
    > <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > <script language="javascript">
    > function ValidateEmail(source, arguments)
    > {
    > if (arguments.Value == "")
    > {
    > arguments.IsValid = true;
    > }
    > else
    > {
    > arguments.IsValid = false;
    > }
    > }
    >
    > function ValidateUsername(source, arguments)
    > {
    > if (arguments.Value == "sally.revell")
    > {
    > arguments.IsValid = true;
    > }
    > else
    > {
    > arguments.IsValid = false;
    > }
    > }
    > </script>
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <table style="WIDTH: 632px; HEIGHT: 208px" borderColor="black"
    > border="1">
    > <tr height="20%">
    > <td align="center" colSpan="3">Table Title</td>
    > </tr>
    > </TR>
    > <tr height="40%">
    > <td width="20%"><asp:label id="lblEmail"
    > runat="server">Email:</asp:label></td>
    > <td width="40%"><asp:textbox id="txtEmail"
    > runat="server"></asp:textbox></td>
    > <td width="40%"><asp:requiredfieldvalidator
    > id="RequiredFieldValidator1" runat="server" ErrorMessage="*"
    > ControlToValidate="txtEmail"
    > EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    > id="CustomValidator1" runat="server" ErrorMessage="Email must be
    > unique" ControlToValidate="txtEmail"
    > ClientValidationFunction="ValidateEmail"
    > Display="Dynamic"></asp:customvalidator></td>
    > </tr>
    > <tr height="40%">
    > <td width="20%"><asp:label id="lblUsername"
    > runat="server">Username:</asp:label></td>
    > <td width="40%"><asp:textbox id="txtUsername"
    > runat="server"></asp:textbox></td>
    > <td width="40%"><asp:requiredfieldvalidator
    > id="RequiredFieldValidator2" runat="server" ErrorMessage="*"
    > ControlToValidate="txtUsername"
    > EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    > id="CustomValidator2" runat="server" ErrorMessage="Username must be
    > unique" ControlToValidate="txtUsername"
    > ClientValidationFunction="ValidateUsername"
    > Display="Dynamic"></asp:customvalidator></td>
    > </tr>
    > <tr height="40%">
    > <td align="center" colSpan="3"><asp:imagebutton id="ImageButton1"
    > runat="server" ImageUrl="images/Ok.gif"></asp:imagebutton></td>
    > </tr>
    > </table>
    > <asp:label id="lblStatus" style="Z-INDEX: 101; LEFT: 16px; POSITION:
    > absolute; TOP: 240px"
    > runat="server" Width="392px"></asp:label></form>
    > </body>
    > </HTML>
    >
    >
    > And here is button click event handler from the C# code behind file:
    >
    > private void ImageButton1_Click(object sender,
    > System.Web.UI.ImageClickEventArgs e)
    > {
    > if (Page.IsValid == true)
    > {
    > lblStatus.Text = "Page is Valid!";
    > }
    > else
    > {
    > lblStatus.Text = "Some of the required fields are empty";
    > }
    > }
    >
    >
    > Has anyone else come across this, and, if so, do you know a fix?
    > Thanks very much!
     
    Sally, Oct 19, 2005
    #2
    1. Advertising

  3. Sally

    Sally Guest

    On further investigation it appears that the problem is due to IIS
    configuration issue on my machine. This same code works fine on other
    machines. I'm not sure what exactly is misconfigured, but will
    investigate further.


    Sally wrote:
    > I've created an ASPX page with 2 textboxes and an OK button. The 2
    > textboxes each have 2 validator controls, a RequiredFieldValidator and
    > a CustomValidator. Both CustomValidator controls link to JavaScript
    > validate methods at the top of the ASPX file (HTML view).
    >
    > With only 1 textbox and its pair of validator controls, the OK button
    > works properly (it displays a status message in a label).
    >
    > However, with the 2 sets of textboxes and associated validator
    > controls, the OK button no longer works. No postback occurs when you
    > click on it.
    >
    >
    > The full text of my ASPX file is as follows:
    >
    > <%@ Page language="c#" Codebehind="Test.aspx.cs"
    > AutoEventWireup="false" Inherits="RecorderLight.Test" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>Test</title>
    > <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > <script language="javascript">
    > function ValidateEmail(source, arguments)
    > {
    > if (arguments.Value == "")
    > {
    > arguments.IsValid = true;
    > }
    > else
    > {
    > arguments.IsValid = false;
    > }
    > }
    >
    > function ValidateUsername(source, arguments)
    > {
    > if (arguments.Value == "sally.revell")
    > {
    > arguments.IsValid = true;
    > }
    > else
    > {
    > arguments.IsValid = false;
    > }
    > }
    > </script>
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <table style="WIDTH: 632px; HEIGHT: 208px" borderColor="black"
    > border="1">
    > <tr height="20%">
    > <td align="center" colSpan="3">Table Title</td>
    > </tr>
    > </TR>
    > <tr height="40%">
    > <td width="20%"><asp:label id="lblEmail"
    > runat="server">Email:</asp:label></td>
    > <td width="40%"><asp:textbox id="txtEmail"
    > runat="server"></asp:textbox></td>
    > <td width="40%"><asp:requiredfieldvalidator
    > id="RequiredFieldValidator1" runat="server" ErrorMessage="*"
    > ControlToValidate="txtEmail"
    > EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    > id="CustomValidator1" runat="server" ErrorMessage="Email must be
    > unique" ControlToValidate="txtEmail"
    > ClientValidationFunction="ValidateEmail"
    > Display="Dynamic"></asp:customvalidator></td>
    > </tr>
    > <tr height="40%">
    > <td width="20%"><asp:label id="lblUsername"
    > runat="server">Username:</asp:label></td>
    > <td width="40%"><asp:textbox id="txtUsername"
    > runat="server"></asp:textbox></td>
    > <td width="40%"><asp:requiredfieldvalidator
    > id="RequiredFieldValidator2" runat="server" ErrorMessage="*"
    > ControlToValidate="txtUsername"
    > EnableClientScript="False"></asp:requiredfieldvalidator><asp:customvalidator
    > id="CustomValidator2" runat="server" ErrorMessage="Username must be
    > unique" ControlToValidate="txtUsername"
    > ClientValidationFunction="ValidateUsername"
    > Display="Dynamic"></asp:customvalidator></td>
    > </tr>
    > <tr height="40%">
    > <td align="center" colSpan="3"><asp:imagebutton id="ImageButton1"
    > runat="server" ImageUrl="images/Ok.gif"></asp:imagebutton></td>
    > </tr>
    > </table>
    > <asp:label id="lblStatus" style="Z-INDEX: 101; LEFT: 16px; POSITION:
    > absolute; TOP: 240px"
    > runat="server" Width="392px"></asp:label></form>
    > </body>
    > </HTML>
    >
    >
    > And here is button click event handler from the C# code behind file:
    >
    > private void ImageButton1_Click(object sender,
    > System.Web.UI.ImageClickEventArgs e)
    > {
    > if (Page.IsValid == true)
    > {
    > lblStatus.Text = "Page is Valid!";
    > }
    > else
    > {
    > lblStatus.Text = "Some of the required fields are empty";
    > }
    > }
    >
    >
    > Has anyone else come across this, and, if so, do you know a fix?
    > Thanks very much!
     
    Sally, Oct 19, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    2
    Views:
    2,289
    John Saunders
    Jun 4, 2004
  2. Joey
    Replies:
    3
    Views:
    3,143
  3. Replies:
    3
    Views:
    1,644
    S. Justin Gengo
    Dec 27, 2005
  4. Jeff Robichaud
    Replies:
    0
    Views:
    386
    Jeff Robichaud
    Mar 7, 2006
  5. John Salerno
    Replies:
    3
    Views:
    621
    John Salerno
    Feb 2, 2006
Loading...

Share This Page