Disable LinkButton on PostBack using JavaScript in ASP.Net

Last Reply 5 days ago By dharmendr

Posted 5 days ago

Hi team,

Please help me to achieve this functionality with linkbutton with fa icon.

Based on link Disable Buttons on PostBack using JavaScript in ASP.Net

 

You are viewing reply posted by: dharmendr 5 days ago.
Posted 5 days ago

Hi Waghmare,

Refer below sample.

HTML

<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Font-Bold="true"
    Text="Submit" ToolTip="Submit" OnClientClick="disableBtn(this.id, 'Submitting...')"
    UseSubmitBehavior="false" CssClass="btn btn-block btn-success" />
<br />
<asp:LinkButton ID="btnSave" runat="server" OnClick="btnSave_Click" class="btn" ToolTip="Delete"
    OnClientClick="disableBtn(this.id, '')" UseSubmitBehavior="false"><i class="fa fa-trash"></i> Trash</asp:LinkButton>
<link rel="stylesheet" media="screen" href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css' />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style type="text/css">
    .btn {
        background-color: DodgerBlue;
        border: none;
        color: white;
        padding: 12px 16px;
        font-size: 16px;
        cursor: pointer;
    }

        .btn:hover {
            background-color: #4CAF50;
        }
</style>
<script type="text/javascript">
    function disableBtn(btnID, newText) {
        Page_IsValid = null;

        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate();
        }
        var btn = document.getElementById(btnID);
        var isValidationOk = Page_IsValid;

        if (isValidationOk !== null) {
            if (isValidationOk) {
                btn.disabled = true;
                btn.value = newText;
            } else {
                btn.disabled = false;
            }
        } else {
            btn.disabled = true;
            btn.value = newText;
        }
    }
</script>

Code

protected void btnSubmit_Click(object sender, EventArgs e)
{
   
}

protected void btnSave_Click(object sender, EventArgs e)
{
    
}

Screenshot