RequiredFieldValidators not being re-evalauated

Posted on 2010-01-05
Last Modified: 2013-12-26
I have a number of text boxes that are validated by required field validators, as well as a submit button. The submit button does a quick Page.IsValid check, and if it is valid, proceeds with my code. Part of my code is to open a ModalPopupExtender which then displays the values that the user entered in the text boxes, and then provides an "OK" and "Cancel" button.

This is just a final review for the user to verify everything they entered was correct. If the user chooses OK, everything proceeds correctly. If the user chooses "Cancel" they are returned to the page to change their data.

In this situation (the user clicks "Cancel") however, the users can erase the data they previously entered from required fields. If they do so, then hit the "Submit" button once again, the field validators on the page are triggered, but my Submit button's Page.IsValid check is bypassed and the ModalPopupExtender appears again, displaying the old data (even though they erased the data in the required fields).

It appears that, since the first page validation was true (all fields were valid) that this valid state is somehow stored, and not re-evaluated when the user returns from clicking the "Cancel" button in the MPE.

Does clicking the "Cancel" button in the MPE automatically exit the "Submit" button's Click Event? Is there a way to tell my application that when the MPE's "Cancel" button is clicked, I should exit the "Submit" button's Click event, and re-evaluate the required fields?

I apologize if that's not very clear, I tried to explain it as simply as I could.
Question by:Brandon_Sidley

    Author Comment

    OK, no responses, so if anyone has suggestions how I can clarify this, I'd appreciate it.. Here's some of my code..

    The "Submit" button, which contains the call to the Modal Popup Extender

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
         'Bunch of variable creation

            If Page.IsValid Then
                'variable assignments from the user input

                'Show Confirmation / Summary Window

                Panel1.Visible = True
                Exit Sub

            End If

        End Sub
    ---------End Submit Button Code--------------

    The MPE Code

    <cc2:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="Button1" DisplayModalPopupID="ModalPopupExtender1" Enabled="True" />
                <cc2:ModalPopupExtender ID="ModalPopupExtender1" runat="server"  Enabled="True"
                    BackgroundCssClass="modalBackground" CancelControlID="CancelButton"
                    OkControlID="OkButton" PopupControlID="Panel1" TargetControlID="Button1" />

    ---------End MPE Code---------------------------

    The Hidden Panel Code (which is the visible portion of the MPE that is displayed)

    <asp:Panel ID="Panel1" runat="server" BorderColor="Black" BorderStyle="Solid"
                   BorderWidth="1px" CssClass="ModalWindow" Height="600px" Visible="False"
                   <span lang="en-us">
                   <asp:TextBox ID="ConfirmTextBox" runat="server" BorderStyle="None"
                       BorderWidth="0px" CssClass="ModalWindowText" ForeColor="White" Height="560px"
                       TextMode="MultiLine" Width="799px"></asp:TextBox>
                   <br />

                   <asp:Button ID="OkButton" runat="server" Text="Ok" CssClass="ButtonsCentered"
                       CausesValidation="False" />
                   <cc2:RoundedCornersExtender ID="OkButton_RoundedCornersExtender" runat="server"
                       Enabled="True" TargetControlID="OkButton">
                   <asp:Button ID="CancelButton" runat="server" Text="Cancel"
                       CssClass="ButtonsCentered" />
                   <cc2:RoundedCornersExtender ID="CancelButton_RoundedCornersExtender"
                       runat="server" Enabled="True" TargetControlID="CancelButton">


    -----------End Hidden Panel Code--------------

    The Code for the MPE/Hidden Panel "Cancel" button (the OK button does nothing right now)

    Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CancelButton.Click
            Panel1.Visible = False
        End Sub
    ------------------END MPE/Hidden Panel Cancel Button Code-------

    Basically here's the control flow..

    A) User enters data
    B) Required Field Validators validate input
    C) If PageIs.Valid=True show the MPE (which is just a confirmation text box with the values entered)
        1. OK Button - No code right now
        2. Cancel Button - Hide the MPE, return back to A) and start over

    However, if the user hits the Cancel button, the MPE goes away, and if the user then erases their original input, and hit submit once more, validation occurs (required field validators are triggered) but the MPE still shows up, and displays the original data that was entered.

    The problem with this is that the MPE should not show up, because the page is not valid (data was erased in required fields), and when the MPE does show up, the data is the "old" data, not empty/erased values.

    Any ideas? I hope that made sense..

    Accepted Solution

    I have resolved this issue. The problem is that in specifying a controlID for the MPE's "cancel" button, it will attempt to use the OnCancelScript event, not the actual code-behind Button_Click event. Removing the value from CancelControlID (changing from CancelControlID="CancelButton" to CancelControlID="") allows the actual Button_Click code to be executed.

    This information was found here.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now