我有asp:LinkButton,输入按钮定义为:
<asp:LinkButton ID="lnkViewPdf" runat="server" CssClass="icoMiniTest" ClientIDMode="Static" >View Office Pdf</asp:LinkButton>
<input id="Button2" type="button" value="TestEnable" onclick="TestEnable(document.getElementById('lnkViewPdf'));" />
LinkButton 最初在代码隐藏中被禁用,如下所示:
if (!IsPostBack)
{
this.lnkViewPdf.Enabled = false;
}
并且需要在单击 Button2 时启用,因此我调用 javascript 函数来启用链接:
function TestEnable(lnkbutton) {
alert('TestEnable() called');
alert(lnkbutton.id);
lnkbutton.disabled = "";
//$("#lnkbutton").removeAttr('disabled'); //even this doesn't work
}
但我无法启用链接按钮。
我错过了什么吗?
谢谢!
____________________________________>_________________ ______
任何有兴趣解决上述问题的人:
在代码隐藏中:
this.lnkViewPdf.Attributes["disabled"] = "disabled";
this.lnkViewPdf.Attributes["onclick "] = "return false";
.js:
function TestEnable(lnkbutton) {
$(lnkbutton).removeAttr('disabled');
lnkbutton.onclick = "";
}
注意:当设置 lnkViewPdf.Enabled = false 时; LinkButton 被渲染为
<a id="lnkViewPdf" class="aspNetDisabled icoMiniTest">View Office Pdf</a>
查看样式类aspNetDisabled,这是由 ASP.Net 添加的
但是,从代码隐藏中设置禁用/onclick 属性(如上所示),将 Linkbutton 渲染为:
<a id="lnkViewPdf" class="icoMiniTest" disabled="disabled" onclick ="return false" href="javascript:__doPostBack('lnkViewPdf','')">View Office Pdf</a>
HTH。
最佳答案
立即尝试...
function TestEnable(lnkbutton) {
lnkbutton.disabled = "";
lnkbutton.onclick = "";
}
关于javascript - 如何启用asp :LinkButton on client side,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6141030/