开发者

Calling jquery function from ascx not working

I'm having a problem with the following situation.

I have an ascx which contains a submit button for a search criteria and I am trying to call a validation function in a js file I've used throughout the site (thi开发者_运维问答s is the first time I'm using it in an ascx).

Now I've just tried this:

<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/jsAdmin_Generic_SystemValidation.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".submitBtn").click(function (e) {
            alert("test");
            alert($.Validate());
            alert("test 2");
        });
    });
</script>

The file is being referenced correctly as I am already seeing posts in Firebug that are done by it.

This is the function:

jQuery.extend({
Validate: function () {
    var requiredElements = $('.required').length; // Get the number of elements with class required

    $('.required').each(function () {
        // If value of textbox is empty and have not
        // yet been validated then validate all required
        // elements. i.e.
        if (($(this).val() == "") || ($(this).hasClass("validationError")) || ($(this).hasClass("validationAlert")) || ($(this).hasClass("validationOk") == false)) {
            validate($(this));
        }
    });

    if ($('.validationOk').length == requiredElements) {
        return true;
    } else {
        return false;
    }
},
// Another extended function, this function
// is used for pages with the edit-in-place
// feature implemented.
validateElement: function (obj) {
    var elementId = obj.attr("id"); // id of the button clicked.
    var flag = 0;

    if (elementId.toLowerCase() == "paymentmethodid") {
        // Case elementId = paymentMethodId then check all the 
        // elements with css class starting with openStorage
        var requiredElements = $(document).find("input[class*='openStorage']").length; // Get the number of elements with css class starting with openStorage

        // Loop through all the elements with css class containing
        // openStorage abd validate each element.
        $(document).find("input[class*='openStorage']").each(function () {
            if (($(this).val() == "") || ($(this).hasClass("validationError")) || ($(this).hasClass("validationAlert"))) {
                validate($(this));
            }

            if ($(this).hasClass("validationOk")) {
                flag++;
            } else if (($(this).hasClass("validationError")) || ($(this).hasClass("validationAlert"))) {
                flag--;
            }
        });

        // If all elements are valid return true else return false
        if (flag == requiredElements) {
            return true;
        } else {
            return false;
        }
    } else if (elementId.toLowerCase() == "registeredfortax") {
        if (($('.TaxRegistrationNumber').val() == "") || ($('.TaxRegistrationNumber').hasClass("validationError")) || ($('.TaxRegistrationNumber').hasClass("validationAlert"))) {
            validate($('.TaxRegistrationNumber'));
        }

        if ($('.TaxRegistrationNumber').hasClass("validationOk")) {
            return true;
        } else {
            return false;
        }
    } else {
        var elementClass = "." + elementId;

        if (($(elementClass).val() == "") || ($(elementClass).hasClass("validationError")) || ($(elementClass).hasClass("validationAlert")) || ($(elementClass).hasClass("validationOk") == false)) {
            validate($(elementClass));
        }

        if ($(elementClass).hasClass("validationOk") && ($(elementClass).hasClass("required"))) {
            return true;
        } else if ($(elementClass).hasClass("required") == false) {
            return true;
        }else {
            return false;
        }
    }
}
});

Now at first I was getting "Validate() is not a function" in firebug. Since I did that alert testing, I am getting the first alert, then nothing with no errors.

Can anyone shed some light?

Thanks


Are you using the extend method properly? ... http://api.jquery.com/jQuery.extend/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜