2

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>&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>
Mike
  • 713
  • 6
  • 20
  • 41

1 Answers1

4

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.

Chris Mullins
  • 6,677
  • 2
  • 31
  • 40
  • Sorry about that, they are all consistent, I just was trying to shorten it up for the code I posted. – Mike Nov 08 '10 at 16:34
  • I copied your code into a new website using and made all of the validation group names consistent, and it works like it should each button only validates whatever is on it's tab. – Chris Mullins Nov 08 '10 at 17:56
  • How did you fire the validation groups? I use the following in my codebehind: – Mike Nov 08 '10 at 19:04
  • btnSave.Attributes.Add("onclick", "return StartProgressBar()") btnPayoffUpdate.Attributes.Add("onclick", "return StartProgressBar()") – Mike Nov 08 '10 at 19:05
  • Hmm the code you included above did not include the javascript on the button click. Maybe that is why it worked for me and not you. I will have to do more testing if I get time. – Chris Mullins Nov 08 '10 at 19:33
  • Mine fired because my buttons did not have the onclick attributes from your codebehind, but I updated my test code to account for the extra javascript, and I think I see the problem, the javascript function does not accept the validation group as a parameter, so each button is calling the validation group in the javascript. – Chris Mullins Nov 08 '10 at 20:58
  • Augghhhhh can't believe I missed that. THANK YOU so much for finding that. – Mike Nov 09 '10 at 13:27