Solved

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

Posted on 2010-08-24
1
698 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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