Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  136] [ 1]  / answers: 1 / hits: 15360  / 10 Years ago, wed, march 12, 2014, 12:00:00

I am trying to access control in Master page from Content page(Asp.net) using javascript like this



alert(document.getElementById('<%=((Label)Master.FindControl(lbl)).ClientID %>').value);


control in Master page is as follow,



 <asp:Label ID=lbl runat=server Text=one></asp:Label>


But unfortunately it is not working. I am getting undefined value


More From » asp.net

 Answers
2

I noticed that you are actually accessing the .value field of the element that the <asp:Label /> control generates, which is a <span></span>. This type of element won't return anything for the .value attribute. If you are actually trying to access its text then use:



alert(document.getElementById('<%=((Label)Master.FindControl(lbl)).ClientID %>').innerText);


or



alert(document.getElementById('<%=((Label)Master.FindControl(lbl)).ClientID %>').innerHTML);

[#72027] Tuesday, March 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dillionsalvadorg

Total Points: 288
Total Questions: 103
Total Answers: 75

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;