本文介绍了如何防止双击asp.net按钮..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试很多没什么可行的。



需要防止双击按钮。



需要如果点击完成clickEvent需要启用true,那么很快就会启用false



Tried Many nothing working Out.

Need to prevent button from double click.

need to enable false as soon ias it got clicked an need to enable true as soon as completion of clickEvent

<asp:Button ID="btnSave" runat="server" CssClass="button" TabIndex="10" Text="<%$ Resources:LocalStrings,Save %>" OnClientClick="return validate()" OnClick="btnSave_Click" />








页面加载时








on page load

btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");







javscript方法验证..






javscript method validate..

function validate() {

           if (document.getElementById('<%=ddlstocktype.ClientID%>').selectedIndex == 0) {

               alert('<%= Resources.LocalStrings.SelectStockType %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddlstocktype.ClientID%>').focus();
               });
               return false;
           }
           else if (document.getElementById('<%=ddllibdept.ClientID%>').selectedIndex == 0) {
               alert('<%= Resources.LocalStrings.SelectDepartment %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddllibdept.ClientID%>').focus();
               });
               return false;
           }
           else if (document.getElementById('<%=ddllibsect.ClientID%>').selectedIndex == 0) {
               alert('<%= Resources.LocalStrings.PleaseSelectSector %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddllibsect.ClientID%>').focus();
               });
               return false;
           }

           else if (document.getElementById('<%=txtName.ClientID%>').value.trim().length == 0) {
               alert('<%= Resources.LocalStrings.EnterName %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=txtName.ClientID%>').focus();
               });
               return false;
           }
           else if (document.getElementById('<%=txtName.ClientID%>').value == "Please Select") {
               alert('<%= Resources.LocalStrings.SelectBookTitle %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddlbook.ClientID%>').focus();
               });
               return false;
           }
           else if (document.getElementById('<%=ddlbooktype.ClientID%>').selectedIndex == 0) {
               alert('<%= Resources.LocalStrings.PleaseSelectBookType %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddlbooktype.ClientID%>').focus();
               });
               return false;
           }
           else if (document.getElementById('<%=ddlauthor.ClientID%>').selectedIndex == 0) {
               alert('<%= Resources.LocalStrings.SelectAuthor %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddlauthor.ClientID%>').focus();
               });
               return false;
           }

           else if (document.getElementById('<%=ddledition.ClientID%>').selectedIndex == 0) {
               alert('<%= Resources.LocalStrings.EnterEdition %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=ddledition.ClientID%>').focus();
               });
               return false;
           }


           else if (document.getElementById('<%=txtPrice.ClientID%>').value.trim().length == 0) {
               alert('<%= Resources.LocalStrings.EnterPrice %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=txtPrice.ClientID%>').focus();
               });
               return false;
           }

           else if (document.getElementById('<%=txtcopies.ClientID%>').value.trim().length == 0) {
               alert('<%= Resources.LocalStrings.EnterNoofCopies %>');
               $(document.activeElement).bind('click', function () {

                   document.getElementById('<%=txtcopies.ClientID%>').focus();
               });
               return false;
           }
       }

推荐答案









页面加载







on page load

btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");







javscript方法验证..






javscript method validate..

function validate() {

           if (document.getElementById('<%=ddlstocktype.ClientID%>').selectedIndex == 0) {

               alert('<%= Resources.LocalStrings.SelectStockType %>');




这篇关于如何防止双击asp.net按钮..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 16:07