0

in my page ther's a label which on it's content i am basing a decision such as hide an disable a cupple of controls.

there's a

<img src="images/Delete.png" alt="delete" 
   style="height: 18px; width: 24px; cursor:pointer" 
   onclick="deleteRow('<%=row["tId"] %>');" id="imgBut_dltRow" />

i would like to undersand how can i disable the click event *or the img/button response like in :

if(document.getElementById("LBL_isManager").value != "")
disable click event / or totaly disable this "imgBut_dltRow"

i couldnt disable it from code behind cause it has <% %> c# tags so i could not make it runat="server" too . only option is ask for the label value if it's not empty ("") then block that event.

thanks a lot !

LoneXcoder
  • 2,121
  • 6
  • 38
  • 76

1 Answers1

1

Try this - DEMO

document.getElementById("imgBut_dltRow").addEventListener("click", function(e) {
    if ( document.getElementById("LBL_isManager").value != "" ) {
        e.stopImmediatePropagation();
    }
}, false);
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
  • it looks perfectly ok within the demo but in my page it somhow throw "Microsoft JScript runtime error: Unable to get value of the property 'addEventListener': object is null or undefined" – LoneXcoder Sep 24 '12 at 21:39
  • probably because you run your script before the DOM element is actually created - put your JS at the very bottom of the page or wrap it in a DOM ready listener – Zoltan Toth Sep 24 '12 at 21:44
  • this is my control instead of its – LoneXcoder Sep 24 '12 at 21:44
  • i think thats the issue ? aspText box should be actualy = input type = textbox... and issue with runat=server could be a problem to implement your code on it? – LoneXcoder Sep 24 '12 at 21:47
  • that is when i put code out of page then page is rendering without the error . this is the view source of how it rendered it – LoneXcoder Sep 24 '12 at 21:54