Click here to Skip to main content
16,004,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi my HTML tag as
<table><thead><th id="UltraWebGridData_c_0_4" class="abc" hieght="" style="">
<nobr>First Name
</nobr>

<th>
</th></th></thead></table>


I have to get first name as a text in javascript.
also I cant change the above code because it is automatically/dynamically generated by C# code
please suggest me.
Thanks
Posted
Updated 21-Sep-11 19:18pm
v2

If it is dynamically generated by the C# code then you cant get by this way..

Use like this...

JavaScript
document.getElementByID("<%= Element.ClientID %>").innerText or innerHTML


because every control of a asp.net has
ASP.NET
runat="server"
which means that the HTML code for the control is generated by ASp.Net and its id is also generated by C#.
 
Share this answer
 
Comments
Pravinjas 22-Sep-11 3:11am    
Thanks Its working-pravin
Kishore Jangid 22-Sep-11 9:13am    
If its working, then accept the answer in Code Project and upvote the answer
Hi,

You can get any html tag in javascript which are contains Id property

JavaScript
document.getElementByID("Id of that html Tag").innerText or .innerHTML


Try this you can get inner html tags or inner text within that tag k


All the best
 
Share this answer
 
Comments
Pravinjas 22-Sep-11 1:19am    
It is not working.
As the other user said, you can get the value using the document.getElementByID method.
(Similarly getElementByTagName method can also be used. But that will return all the specified tags.)

In your case, you need to surround the text inside a span (or even div). Give it an id and use the above methods.
Something like:
HTML
<span id="spnFirstName">FirstName</span>
 
Share this answer
 
Comments
[no name] 22-Sep-11 2:29am    
hi already describe that "I cant change the above code because it is automatically/dynamically generated by C# code"
Ankur\m/ 22-Sep-11 5:30am    
And he did that after my answer. Check the previous version of the question. You must analyse things properly before you vote 1.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900