How to access the server control of content page inside the javascript?
Hello,
Sometime i used to create websites using Master Page. Some server controls are added into content page. For some cases i need to use to change the value of those control at client side. So usually write javascript code.
For example : Suppose i want to add two number and show the result. I want to perform addition in client side and show the result on content page’s Label control.
for this first i wrote the below code :
function addNumber(val1,val2)
{
var result=val1+val2;
document.getElementById('Label1').innerHTML = result;
}
But the above code gives javascript error. i.e : unrecognised id.
Because the content page’s control id converted as per contentplace holder id.
So i modified the code to below code.
function addNumber(val1,val2)
{
var result=val1+val2;
document.getElementById('<%=Label1.ClientID%>').innerHTML = result;
}
The above code works fine.
so whenever you want to access the content page’s control at client side just put the clientID of that control not the control id only.
