Solved

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

Posted on 2010-08-24
1
687 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now