ASP.NET: Confirm PostBack OnClientClick Button


ASP.Net Button:

<asp:Button ID="btnSubmit" runat="server" class="unrulyBtn" Text="Submit" OnClientClick="if ( ! btnSubmitonClickEvent()) return false;" OnClick="btnSubmit_Click" CausesValidation="True" />


Java Script Method:

function btnSubmitonClickEvent() {
        if (confirm('Once submitted, Flight Report for this sector cannot be edited.')) {
         // We can't use disable here because if we make that button as disabled, In that case OnClick will not work.
         // $('[id$=btnSubmit]').attr("disabled", "disabled");            
            $('[id$=btnSubmit]').attr("style", "display:none");
            return true;
        }
        else {
            //   $('[id$=btnSubmit]').removeAttr('disabled');
            $('[id$=btnSubmit]').attr("style", "display:block");
            return false;
        }
    }

Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell