2

我有一个带有 2 个验证组的简单 2 个选项卡面板设置。我的问题是我的按钮触发了两个验证组。

<cc1:TabPanel ID="TP2" runat="server" HeaderText="" Enabled="true">
 <HeaderTemplate>Loan Main</HeaderTemplate>
  <ContentTemplate>
    <table cellpadding="3" cellspacing="1">
      <tr>
        <td style="text-align: right"> Quality:</td>
        <td><asp:DropDownList ID="ddlAssignedRep" runat="server" DataSourceID="SqlDataSourceAssignedRep" 
                 ValidationGroup="TP2" DataTextField="CreatedBy" DataValueField="CreatedBySFID" 
                AppendDataBoundItems="True"> </asp:DropDownList>
          <asp:SqlDataSource ID="SqlDataSourceAssignedRep" runat="server" ConnectionString="<%$ ConnectionStrings:EUCNET00720 %>" 
        SelectCommand="SELECT distinct [CreatedBySFID], [CreatedBy] FROM [tblRefiActions] WHERE ([RefiPkey] = @RefiPkey) ORDER BY [CreatedBy]">
            <SelectParameters>
              <asp:QueryStringParameter Name="RefiPkey" QueryStringField="Pkey" Type="Int32" />
            </SelectParameters>
          </asp:SqlDataSource></td>
      </tr>
      <tr>
        <td style="text-align: right"><asp:Button ID="btnSave" runat="server" ValidationGroup="TP2" Text="Save" /></td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Quality measure is required." 
    ValidationGroup="TP2" ControlToValidate="ddlQuality" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator>
  </ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TP3" runat="server" HeaderText="" Enabled="true">
  <HeaderTemplate>Short Payoff</HeaderTemplate>
  <ContentTemplate>
    <table cellpadding="3" cellspacing="1">
      <tr>
        <td style="text-align: right"> Amount Short:</td>
        <td><asp:TextBox ID="txtShortPayoffAmount" ValidationGroup="TP3" runat="server" Columns="12" MaxLength="12"></asp:TextBox></td>
      </tr>
      <tr>
        <td style="text-align: right">&nbsp;</td>
        <td><asp:Button ID="btnPayoffUpdate" runat="server" Text="Update" ValidationGroup="TP3" /></td>
      </tr>
    </table>
    <br />
    <br />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
    ErrorMessage="Amount can only contain numbers and a single decimal point." ControlToValidate="txtShortPayoffAmount" 
    ValidationGroup="TP3" Display="None"  SetFocusOnError="True"
    ValidationExpression="^(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$"> </asp:RegularExpressionValidator>
  </ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True" 
     ValidationGroup="TP2" ShowSummary="False" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List" 
     ValidationGroup="TP3" ShowMessageBox="True" ShowSummary="False" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <div>
      <cc1:ModalPopupExtender ID="ProgressBarModalPopupExtender" runat="server" BackgroundCssClass="ModalBackground" BehaviorID="ProgressBarModalPopupExtender" TargetControlID="hiddenField1" PopupControlID="Panel1" />
      <asp:Panel ID="Panel1" runat="server" Style="display: none; background-color: #C0C0C0;"> <img id="MyImage" src="../Images/Vista_Searching_Bar.gif" alt="" />
        <div id="processMessage" style="width: 200px;"> <br />
          <br />
          &nbsp;&nbsp; Loading...<br />
          <br />
        </div>
      </asp:Panel>
      <asp:HiddenField ID="HiddenField1" runat="server" />
    </div>
  </ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">

         function StartProgressBar() {
            var tp2 = Page_ClientValidate("TP2")
            if (tp2 == true) {
                 var myExtender = $find(    ProgressBarModalPopupExtender    );
                 ProgressImg = document.getElementById(    MyImage    );
                 setTimeout("ProgressImg.src = ProgressImg.src", 10);
                 myExtender.show();
                 return true;
             }
         }

    </script>
4

1 回答 1

4

我认为您的验证组名称已关闭。按钮和验证摘要显示验证组“TabPanel3”“TabPanel1”,但您的验证器显示“TP3”和“TP2”

此外,您需要确保按钮单击中的 javascript 已传入 ValidationGroup。根据下面的评论,无论您单击哪个按钮,它现在看起来好像正在调用“TP2”。

试试这个为你的 javascript

 function StartProgressBar(ValidationGroup) {
        if (Page_ClientValidate(ValidationGroup)) {
            //do stuff here on valid

            return true;
        }
        else {
            return false;
        }
    }

然后你的按钮点击代码应该是这样的:

<asp:Button ID="btnSave" OnClientClick="return StartProgressBar('TP2');" runat="server" ValidationGroup="TP2" Text="Save" />

and 

<asp:Button ID="btnPayoffUpdate" OnClientClick="return StartProgressBar('TP3');" runat="server" Text="Update" ValidationGroup="TP3" />

使每次单击都返回验证的值,这样单击将不会继续,因为如果您从该函数返回 true,即使验证失败我也不确定它是否会停止,因为您手动调用了验证,我不知道如果它会再次运行。但是如果你返回 false 它将停止点击,或者至少它应该停止。

于 2010-11-08T16:16:25.587 回答