CyberK
CyberK

Reputation: 1578

asp:Linkbutton enables but is not clickable

I don't know if this is a bug or whatever, but how can I call the event in the code-behind after enabling the linkbutton?

This is my linkbutton:

<asp:LinkButton ID="btnStartImportNow" runat="server" OnClick="btnStartImportNow_Click" Enabled="false">
    <div class="css_action_item_enabled" style="float: right;">
    <div class="css_action_item_icon_add">
    </div>
    <span class="css_action_link">
    <asp:Label runat="server" ID="lblStartImport">
    </asp:Label>
    </span>
    </div>
</asp:LinkButton>

Now I have a javascript with this rule:

document.getElementById(clientId + "_btnStartImportNow").disabled = false;

Well the button enables, but I cannot click the button... What is wrong?!?

Thanks in advance!

Upvotes: 0

Views: 3797

Answers (2)

Shadow Wizzard
Shadow Wizzard

Reputation: 66398

You can also do that server side. Remove the Enabled="False" from the tag and add this line in the Page_Load event instead:

btnStartImportNow.Attributes["disabled"] = "disabled";

Client side solution is good but has several downside:

  1. Won't work when user disabled scripting in the browser
  2. Cross browser issues

Upvotes: 0

CyberK
CyberK

Reputation: 1578

Set the disabled property in the window.load so the _doPostback gets registered before the button gets disabled which causes the _doPostback to skip his registration :D

Upvotes: 1

Related Questions