所有按钮都调用验证组

发布于 2024-09-30 19:22:09 字数 4601 浏览 1 评论 0原文

我有一个简单的 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>

I have a simple 2 tab panel setup with 2 validation groups. My problem is that my buttons fire both validation groups.

<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> </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"> </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 />
             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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

π浅易 2024-10-07 19:22:09

我认为您的验证组名称已关闭。按钮和验证摘要显示验证组“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,它将停止点击,或者至少应该停止。

I think your validation group names are off. The button and validation summary say the validation group "TabPanel3" "TabPanel1" but your validators say "TP3" and "TP2"

Also you need to make sure that the javascript in your button click is having the ValidationGroup passed in. It looks as though right now it is calling "TP2" no matter which button you click based on your comments below.

Try this for your javascript

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

            return true;
        }
        else {
            return false;
        }
    }

Then your button click code should be something like this:

<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" />

Make each click return the value of the validation, that way the click will not continue, because if you return true from that function even if the validation fails I am not sure it will stop since you called the validation manually, I don't know if it will run again. But if you return false it will stop the click, or at least it should.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文