Click here to Skip to main content
16,017,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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



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;
           }
       }
Posted
Updated 19-Apr-14 2:00am
v4

1 solution

 
Share this answer
 
v2
Comments
Member 10690248 19-Apr-14 6:37am    
i already tried this not working as i have one more fuction call upon client click
kedar001 19-Apr-14 7:07am    
can you post your code snippet
Member 10690248 19-Apr-14 7:56am    
<pre> <asp:Button ID="btnSave" runat="server" CssClass="button" TabIndex="10" Text="<%$ Resources:LocalStrings,Save %>"
OnClientClick="return validate()" OnClick="btnSave_Click" />
</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900