ModalPopup中的RequiredFieldValidator导致问题

时间:2011-05-05 19:34:25

标签: asp.net ajax validation

我有一个ASP.NET 3.5表单,其中包含几个字段和一个ModalPopup中的子表单。我遇到的问题是在ModalPopup中使用RequiredFieldValidator。由于某种原因,它阻止了回传到ModalPopup中。验证器和提交按钮都具有相同的ValidationGroup。这是子表单的标记:

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

当删除验证器(或将CausesValidation设置为false)时,子表单发布。 RegularExpressionValidators没有这个问题。我运行FireBug,但我没有看到任何明显的错误。

我有什么遗失的吗?

3 个答案:

答案 0 :(得分:2)

天啊,我太傻了! &GT;:(

找到问题的原因。在另一个控件中嵌套了另一个相同控件的副本。并且(当然)具有与我的第一个控件相同的ValidationGroup名称,所有必需的字段验证器都无法工作!

哎呀!每日WTF的候选人!

很抱歉浪费了每个人的时间:(

答案 1 :(得分:1)

您能否检查一下打开弹出窗口和modaldialog扩展器的Button(或其他控件)是否在更新面板之外?

答案 2 :(得分:1)

我也遇到了modalpopup的奇怪问题。我建议你尝试不同的东西,例如ajaxcontroltoolkit中的numericupdown控件,如果你已经使用过它。所以你不需要任何验证器。

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