开发者

RequiredFieldValidator inside ModalPopup causing problems

开发者 https://www.devze.com 2023-03-03 10:39 出处:网络
I have an ASP.NET 3.5 form with several fields and a sub form inside a ModalPopup. The problem I\'m having is with a RequiredFieldValidator inside the ModalPopup. For some reason it is preventing post

I have an ASP.NET 3.5 form with several fields and a sub form inside a ModalPopup. The problem I'm having is with a RequiredFieldValidator inside the ModalPopup. For some reason it is preventing post back inside the ModalPopup. Both the validator and the submit buttons have the same ValidationGroup that is unique to them. Here is the markup for the su开发者_如何学Gob form:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RoomBuilder.ascx.cs" Inherits="Admin_Controls_RoomBuilder" %>
<link href="../../../../style/FlexStyle.css" rel="stylesheet" type="text/css" id="style"
    runat="server" visible="false" />
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="form" style="width: 420px; height: 500px; padding: 3px; position: relative;
            text-align: center;">
            <div style="width: 280px">
                <div class="item smalltitle ">
                    Title:

                </div>
                <div class="item">
                    <asp:TextBox ID="txtTitle" runat="server" Width="250px"></asp:TextBox>
                </div>
                <div class="item smalltitle gapontop">
                    Description:
                </div>
                <div class="item">
                    <asp:TextBox ID="txtDesc" runat="server" Width="250px" Height="40px" TextMode="MultiLine"></asp:TextBox>
                </div>
                <div class="item gapontop">
                    <div class="smalltitle floatLeft" style="width: 120px;">
                        Room Number
                    </div>
                    <div class="smalltitle floatLeft" style="width: 120px;">
                        Phone
                    </div>
                </div>
                <div class="item">
                    <div class="floatLeft" style="width: 120px;">
                        <asp:TextBox ID="txtRoomNo" runat="server" Width="100px"></asp:TextBox>
                    </div>
                    <div class="floatLeft" style="width: 120px;">
                        <asp:TextBox ID="txtPhone" runat="server" Width="100px"></asp:TextBox>
                    </div>
                </div>
                <div class="item smalltitle gapontop ">
                    Type:
                </div>
                <div class="item">
                    <asp:TextBox ID="txtType" runat="server" Width="250px"></asp:TextBox>
                </div>
                <div class="item smalltitle gapontop ">
                    Number of Seats:
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatortxtNoSeats" runat="server" ErrorMessage="*" 
                        ControlToValidate="txtNoSeats" ValidationGroup="roomVal"></asp:RequiredFieldValidator>
                </div>
                <div class="item">
                    <asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Not a number"
                        ControlToValidate="txtNoSeats" ValidationGroup="roomVal" ValidationExpression="[0-9]*"></asp:RegularExpressionValidator>
                </div>
            </div>            
            <!-- ************************************ -->
            <div class="topBorder" style="width: 100%; height: 35px; position: absolute; bottom: -8px;
                right: 2px; text-align: right; padding-top: 11px;">
                <asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" CausesValidation="false"
                    OnClick="btnCancel_Click" ValidationGroup="roomVal" />
                <asp:Button ID="btnSave" runat="server" CssClass="button" Text="Save" OnClick="btnSave_Click" CausesValidation="true" ValidationGroup="roomVal" />
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

When the validator is removed (or CausesValidation is set to false), the sub form posts. RegularExpressionValidators don't have this problem. I've run FireBug, but I'm not seeing any obvious errors.

Is there something I'm missing?


Oh my god I'm so stupid!! >:(

Found the reason for the problem. There was another copy of the same control nested inside another control. And (of course) having the same ValidationGroup name as my first control all Required Field Validators fail to work!

Argh! Candidate for a Daily WTF!

Sorry to have wasted everybody's time :(


Can you please check if your Button (or some other control) that open the popup and the modaldialog extender are outside the update panel?


I got strange problems with modalpopup too. I would suggest you to try something different, for example a numericupdown control from the ajaxcontroltoolkit, if you already use it. So you don't need any validator for this.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<div class="item smalltitle gapontop ">
                    Number of Seats:
                </div>
                <div class="item">
                    <asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>             
                    <cc1:NumericUpDownExtender ID="txtNoSeatsExt" runat="server"
                        Enabled="true" Minimum="1" Maximum="100" TargetControlID="txtNoSeats" Width="50" />
                </div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号