简体   繁体   English

如何使用javascript检查必填字段?

[英]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. 我有一个asp.net网页,我的要求是显示加载图像,直到单击“提交”按钮后gridview加载数据为止。 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". 但是现在的问题是:当用户单击“提交”按钮时,它不会检查必填字段,并且会一直显示加载符号,直到或除非我们使用“ 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. 我正在使用ASP的RequiredFieldValidator来检查必填字段,并且它与“提交”按钮可以正常工作,但是只有加载模式不考虑那些必填字段。 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 . 在您的jquery click事件上,将此条件与ValidationGroup名称一起放置。 here val is my ValidationGroup name val是我的ValidationGroup名称

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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