简体   繁体   中英

enabling ASP.NET hyperlink using javascript

I use VS2010,C# to develop my ASP.NET web app, I've created an asp.net hyperlink like this:

<asp:HyperLink ID="hpAccept" runat="server" Enabled="false" Target="_parent">Hyperlink</asp:HyperLink>

as you can see I've defined it as enabled=false, so it is disabled at startup, I've defined a JavaScript function that should enable this hyperlink after a variable is set to true, but it doesn't work! what is my problem, it is my JS function:

           function onRadioChange(rowIndex, value) {

.....
....
           if (all_ok) {
               document.getElementById('hpAccept').disabled = false;
           }
       }

my variable (all_ok) is set to true but the hyperlink is not enabled!

thanks

The element's id will not be 'hpAccept'

instead use:

document.getElementById('<%=hpAccept.ClientID%>').disabled = false;

<%= hpAccept.ClientID %> should work but not in a separate javascript file where server side scripts do not execute.

Another possibility is to use a class selector: jQuery

<input runat="server" id="hpAccept" value="test" class="txtTest" />

and then:

var value = $('.txtTest').removeAttr('disabled'); //Updated

Hope this helps.

You should add to your HyperLink markup attribute ClientIDMode with value static, it must be looks like this

<asp:HyperLink ID="hpAccept" runat="server" Enabled="false" ClientIDMode="Static" Target="_parent">Hyperlink</asp:HyperLink

After that, you can use jquery

$("#hpAccept").attr("disabled", "disabled");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM