Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just want to say how much I value your site. I hope the good work keeps up there. It's really helped me..."

Geography

Where in the world do Tek-Tips members come from?

JavaScript to validate <asp:CustomValidator>

BunBo900 (MIS)
26 Jan 12 11:14
Hello:

I am trying to modify existing pages. I just added in a search capaibility to the page. This page rather complicate and lengthy to me.  This page is using <ajaxToolkit:modal>
to process information. Everything is working fine except when
I have the JavaScript function ensureChecked() added to validate the checkbox making sure the user clicks on the checkbox before proceed to submit this causes the search capaiblity not to work.  Is there work around this with out the need of JavaScript function ensureChecked() being called from <asp:CustomValidator>  but still achieve what I want?  Let me know if this confuses you....Thanks.


<script type="text/javascript">

        function ensureChecked(source, args) {
            var cb = document.getElementById('<%=cbxAgreement.ClientID%>');

            if (cb.checked == true) {
                args.IsValid = true;

            } else {
                args.IsValid = false;
           }
        }
        
</script>


<asp:Panel ID="pnlEnrollmentAgreement" runat="server" Width="400px" Height="300px"
                    Style="display: none">
                    <table>
                        <tr>
                            <td align="left" valign="top">
                                <asp:Label ID="lbAgreementHeader" runat="server" Width="100%" BackColor="#E2E3C2"
                                    ForeColor="Black" CssClass="linkStyle" Font-Size="14px" Text="<b>Step 3</b> - Enrollment Agreement"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:CheckBox ID="cbxAgreement" runat="server" Text="I have received pre-enrollment counseling and will notify the appropriate training." /><br />
                                <br />
                                <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ensureChecked"
                                    ErrorMessage="* Please read then check the agreement to continue"></asp:CustomValidator>
<br />
                                <br />
                                <br />
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <asp:Button ID="btnSubmit" runat="server" Text="Enroll in this Course!" OnClick="btnSubmit_OnClick" />
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
MarkSweetland (MIS)
26 Jan 12 13:11

I think I get what you're asking...

If your search function employs a "Search Button" where the user enters text in a textbox and clicks a separate button (other than the Submit button), set the CausesValidation="false" in the Search button propterties.  This bypasses the CustomValidator OnClientClick when the Search button is clicked but leaves it to operate normally when the user clicks the Submit button.



 


     Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach

cornboy88 (Programmer)
17 Feb 12 12:57
Forget the Custom Validator


CODE


<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%= btnSubmit.ClientID %>').click(function () {
                if ($('#<%= cbxAgreement.ClientID %>').is(":not(:checked)")) {
                    alert("* Please read then check the agreement to continue");
                    return false;
                }

            });
        });
    </script>

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close