views:

288

answers:

1

Hiya,

I am using the AJAX Cascading drop down list but want to add event validation e.g. the compare validators.

As the cascading drop down list requires the page event validation to be disabled what is the best way to do the validation?

Thanks

Andy

Validation Attempt: I have tried to use a custom validator which calls a Javascript function but it doesnt seem to be picking up the control. I get the following error Microsoft JScript runtime error: Object required

function ValidateCostCentCat(source, arguments) 
{
  var countryList = document.getElementById("ddlCategory");
  if (null != countryList) 
  {
    var iValue = countryList.options[countryList.selectedIndex].value;
    if (iValue == "Select Category") 
    {
      arguments.IsValid = true;
    } 
    else 
    {
      arguments.IsValid = false;
    }
  }
}

The mark-up for the custom validator is

<asp:CustomValidator ID="valcustCategory" runat="server" CssClass="error" Display="Dynamic" ValidationGroup="DirectHire" ClientValidationFunction="ValidateCostCentCat"
          ErrorMessage="Please select a Cost Centre Category from the drop down list provided.">!</asp:CustomValidator>
+1  A: 

Read This: http://www.w3schools.com/PHP/php_ajax_database.asp

The example demostrate how to select a value from a dropdown box sent it via AJAX and get back the responce!

in the middle you can do all the Validation that you want!

UPDATED with code just for fun! ;-)

Assuming your select is

<asp:DropDownList ID="CategoryDropDownList" runat="server">

Then you function look like this:

function ValidateCostCentCat(source, arguments)
{
    var countryList = document.getElementById("CategoryDropDownList");
    if (null != countryList)
    {

    var iValue = countryList.options[countryList.selectedIndex].value;

    if ( iValue == "Select Category" ) {

    arguments.IsValid = true;

    } else {

    arguments.IsValid = false;

    }
  }
}

This must work as expected!

hope this help!

aSeptik
I have tried using a custom validator control using client validation but I cant get it to see the drop down list. I have posted my code at the bottom of the above question.Thanks
anD666
see the updates!
aSeptik
I have updated to suit your code! Let me know!
aSeptik
I have tried both examples you gave but neither work, its not picking up the drop down list. There is nothing special about it I just use a web method to fill it and use the AJAX cascading drop down list controls.Sorry for slowness on this, I havent tried client validation or using custom validators before.Thanks
anD666
I have tried commenting out the conditional statement which checks to see if countryList is null which confirms the client script isnt finding ddlCategory
anD666