I am working on an asp.net project where I need to be able to disable several hyperlink controls on the fly in javascript when the user starts a transaction. I don’t want them to be clicking links in the middle of it – accidental or not.
I have researched and tried several things that have not worked. This involved setting the “enabled” property to false, “disabled” properlty to true and settign the .href property to “#”. None of these worked.
I then discovered that even trying to access the hyperlink field using “document.getelementbyid” was unsuccessful, so this could be HUGE of the issue…
I tried using the following… (also tried using the clientid and still no go)
var myHL = document.getElementById("MainContent_hl_first"); (doesn’t seem to work)
myHL.enabled = false (doesn’t work because above assignment doesn’t work)
myHL.disabled=false(ditto)
also tried…
document.getElementById("MainContent_hl_first").enabled=false; (doesn’t work)
also tried
document.getElementById("MainContent_hl_first").disabled = false; (doesn’t work)
As a test, I hard coded an “onclick” event into the html code like below it works… So how can I add this on the fly in javascript, keeping in mind that accessing the control using the document.getelementbyid doesn’t seem to work? (because otherwise I could have just set the .onclick event…)
<asp:HyperLink ID="hl_first" onclick=”return false” runat="server" ImageUrl="~/Images/nav_first.gif"></asp:HyperLink>