Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all
when we should be use of document.getElementById
for asp.net control or html control? (or both of them and why?)
thanks for any answer
Posted
Updated 17-Apr-13 21:02pm
v2
Comments
Prasad Khandekar 18-Apr-13 3:09am    
document.getElementById is a HTML DOM api for JavaScript. You use it in javascript to find a particluar element by value of it's it's id attribute. Asp.Net control finally gets rendered as an HTML element. You can use this API for both ASP.NET Web Control and Html Control.
mhd.sbt 18-Apr-13 10:17am    
ok thank you for reply
i have an span tag for example with id=span1 i want to set display =none .
witch of two below code you preferred?
1-
var span=document.getElementById('span1');
span.style.cssText="Display:none";
or
2-
span1.style.cssText="Display:none";
and why?

Hi,
refer the msdn article regarding this function.
getElementById method[^]
HtmlDocument.GetElementById Method [^]

hope it helps.
 
Share this answer
 
 
Share this answer
 
hi pal ,

document.getElementById('aspControl or htmlcontrol').value

Here we getting the value of that control
most of the time we are using for validations means form validations

document.form1.getElementById('aspControl or htmlcontrol').value
we can like this also for finding value(text) of a control we are using...

document.getElementById --for id
document.getElementByName ---for name
document.getElementByTag ...etc

we have like this methods in javascript library
 
Share this answer
 
v2
Comments
mhd.sbt 18-Apr-13 10:17am    
ok thank you for reply
i have an span tag for example with id=span1 i want to set display =none .
witch of two below code you preferred?
1-
var span=document.getElementById('span1');
span.style.cssText="Display:none";
or
2-
span1.style.cssText="Display:none";
and why?

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