SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CustomValidator and Javascript Client function

    In my ASP.net page I am using Customvalidator control and through this control I am trying to call the client side javscript function which tests whether any checkbox in checkboxList controls is selected or not. is not selected then I need to flash a message and do not let the user submit the page.

    the Javscript code is working fine as I have tested it properly. It however looks like the CustomValidator is not calling this Javascript code. Please help. here is the code:

    '---------Javascript code:

    <script type="text/javascript">
    function CheckState(source,args)
    {
    var boolChecked;

    for(var i = 0; i < 9; i++)
    {
    if($('ctl00_ContentPlaceHolder1_CheckBoxList1_' + i).checked == false)
    {
    boolChecked = false;
    }
    else
    {
    boolChecked = true;
    break;
    }
    }

    if (boolChecked==false)
    {
    alert('Please select some System keyword');
    args.IsValid = false;
    return false;
    }
    else
    {
    args.IsValid = true;
    return true;
    }
    }
    </script>


    '------------CodeValidator
    <div><asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="At least one Area is to be selected." ClientValidationFunction="CheckState" ValidateEmptyText="True"></asp:CustomValidator></div>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Should this be asked about on the ASP forum?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry. I guess you are correct. Any ways, after so many hours of fighting with the code in my project I have discovered that this code is correct and there is something in my master Page that is not letting this code work properly. So I will have to debug that process now. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •