[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

RequiredFieldValidators not being re-evalauated

Posted on 2010-01-05
2
Medium Priority
?
324 Views
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.
0
Comment
Question by:Brandon_Sidley
  • 2
2 Comments
 

Author Comment

by:Brandon_Sidley
ID: 26193117
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
            ModalPopupExtender1.Show()
            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"
               Width="800px">
               <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 />
               </span>

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

           </asp:Panel>

-----------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..
0
 

Accepted Solution

by:
Brandon_Sidley earned 0 total points
ID: 26193986
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.
http://tiredblogger.wordpress.com/2007/02/27/modalpopupextender-button-or-anything-events/
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 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