Solved

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

Posted on 2010-08-24
1
694 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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