Link to home
Create AccountLog in
Avatar of Sailing_12
Sailing_12

asked on

Get .net custom attribute value with javascript

I have hyperlinks structured as below being generated by .net - I need to get the contactid attribute value using a javascript function and pass it to an iframe.

I can figure out the iframe part - having trouble getting the value. Can someone help me? Thanks.

switchMember(){
    getNotes();
    // get contactid value for link which was clicked
    // pass it to iframe
}
<a onclick="switchMember();" id="gvFamily_ctl03_lbMember" contactid="61A0B8F7-29C9-DC11-8BFA-0003FF947908" href="javascript:__doPostBack(&#39;gvFamily$ctl03$lbMember&#39;,&#39;&#39;)">Maria Jones</a>

Open in new window

Avatar of iHadi
iHadi
Flag of Syrian Arab Republic image

try the following javascript:

var ctrl = document.getElementById('<%# LbMember.ClientID %>');
var val = ctrl.getAttribute('contactid');

alert(val);

Avatar of Sailing_12
Sailing_12

ASKER

The page won't compile with that - 'lbMember is not declared. It may be inaccessible due to its protection level'
ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Solved this by reconstructing the way the links are built from .net to include and pass contactid with javascript function call.

No longer need to read contactid attribute.