简体   繁体   中英

How to check the mandatory field with javascript?

I have a asp.net web page where my requirement was to show loading image until the gridview loads data after clicking the Submit button. So, I have researched on the internet and managed to this as per below code:

        function ShowProgress() {
        myVar = setTimeout(function () {
            var modal = $('<div />');
            modal.addClass("modal");
            $('body').append(modal);
            var loading = $(".loading");
            loading.show();
            var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
            var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
            loading.css({ top: top, left: left });
        }, 200);
    }
    $('form').live("submit", function () {
        ShowProgress();
    });

But now the problem is : when user clicks on "Submit" button then it does not check for mandatory field and it keep on showing the loading symbol until or unless we refresh the page using "F5". I am using RequiredFieldValidator of asp to check for mandatory field and it works fine with the Submit button but only the loading modal does not consider those mandatory field. Please suggest me on this how I may achieve this. Thanks in advance.

On your jquery click event put this condition with your ValidationGroup name . here val is my ValidationGroup name

 $('form').live("submit", function () {
if (Page_ClientValidate('val') == true)
{
        ShowProgress();
}
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM