Solved

How do I force validation on an asp .net page from the client side (javascript/jquery)?

Posted on 2010-08-24
1
697 Views
Last Modified: 2013-11-27
Hi:

I would like to be able force validation to fire from my asp .net page.
Basically, I catch the onChange() in a total amount field.
From that point, I'd like to force the ALL individual amount fields' validators to fire.
The individual amounts are contained in a custom user (ascx) control that's embedded in a repeater control.



I know how force validation on a single validator, I'd like to figure out to force it to fire on all the validators
embedded in the repeater control.



My asp .net page looks more or less like this:


===============================================================
This is what my asp:repeater control looks like:
===============================================================
<div id="div1">
    <asp:Repeater ID="Repeater1" runat="server"  >
        <HeaderTemplate>
            <table border="1" width="800px">
                <tr>
                    <td>
                        <strong> Repeater Header</strong>
                    </td>
                </tr>
        </HeaderTemplate>

        <ItemTemplate>
            <tr>
                <td class="indent vmid">
                    <uc1:CustomUserControl ID="CustomUserControl1" runat="server"                
                        Index ='<%# DataBinder.Eval(Container, "ItemIndex") %>'
                        FullName='<%# DataBinder.Eval(Container.DataItem, "FullName") %>'
                    />
                </td>
            </tr>
        </ItemTemplate>
   
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
</div>


===============================================================
This is what a snippet of my custom user control looks like (ascx)
===============================================================

<asp:Label ID="lTravelerTourCenterID" Width="10" runat="server" Visible="false"/>
<asp:Label ID="lFullName" Width="170" runat="server" />
<asp:TextBox ID="tAmount" Width="170" runat="server" />

<asp:RegularExpressionValidator ControlToValidate="tAmount"                         
      ValidationExpression="^[0-9]+(,[0-9]{3})*(\.[0-9]{0,2})*"
    ErrorMessage="Enter a valid amount" runat="server" ID="reValidator" Display="Dynamic" CssClass="error small" />

<asp:CustomValidator ID="cvtIndividualAmountPaxPayment" runat="server" ControlToValidate="tAmount"
      ClientValidationFunction="validatePaxPayments"
    ForeColor=" " CssClass="error small" ErrorMessage="Total pax payments exceed GL's account." Display="Dynamic"/>

<asp:CustomValidator ID="cvtIndividualAmountMinDeposit" runat="server" ControlToValidate="tAmount"  
      ClientValidationFunction="validatePaxMinDeposit" OnServerValidate="OnValidateMinPaxPayment"
    ForeColor=" " CssClass="error small" ErrorMessage="Payment cannot be less than minimal deposit." Display="Dynamic"/>

<asp:CustomValidator ID="cvtIndividualAmount" runat="server" ControlToValidate="tAmount"
      ClientValidationFunction="validateIndividualAmount" OnServerValidate="OnValidateIndividualAmount"
    ForeColor=" " CssClass="error small" ErrorMessage="Enter a valid payment amount" Display="Dynamic"/>

<div class="rowPayment smaller mrgl30" id="PaymentInfoType" runat="server" visible="false">
     <div class="columnA" id="divCheck" runat="server" >
         <exp:Check ID="checkPayment" runat="server" />
     </div>
</div>



Thanks,
JohnB
0
Comment
Question by:jxbma
1 Comment
 
LVL 8

Accepted Solution

by:
Fareed Ali Khan earned 500 total points
ID: 33518423
Hi,

Please assign the validationGroup to controls and CustomValidators, lets suppose 2 textboxes and their CustomValidators have the ValidationGroup "ABC" and the button is also have the same validationGroup "ABC" then whenever button will submit it will verify all the validators who have group "ABC".

for reference please read the following article:

http://www.dotnet-guide.com/validationgroups.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Correct and Effective way to generate pdf files online via JavaScript or ASP.Net? 6 57
Syntax Issue with SSIS module 26 104
Change to file doesn't show up 16 52
Code enhancement 4 22
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question