Javascript code is not working in the Asp Net content page

My following JavaScript Code is not working in the asp.net content page, as it is working fine if i put this code on the page which don't have master page. I can't understand the reason why it is not working on the content page. May be you will know the answer. Please suggest me what to do.

function SelectheaderCheckboxes(headerchk) 
{

var gvcheck = document.getElementById('GridView1');

var i;

if (headerchk.checked) {

for (i = 0; i < gvcheck.rows.length; i++) {

var inputs = gvcheck.rows[i].getElementsByTagName('input');

inputs[0].checked = true;

}

}
}
Posted by Harpreet 7/1/2014 12:05:50 PM
Total Answers : 1
Answer 1
Pass the control Id like this
document.getElementById('<%=GridView1.ClientID%>')
It will solve your problem. It is not working in the content page because in contentplace holder the id of the control changes automatically. For better understanding, go to view source of your html page, then see the id of your controls. this
 function SelectheaderCheckboxes(headerchk) {

var gvcheck = document.getElementById('<%=GridView1.ClientID%>');

var i;

if (headerchk.checked) {

for (i = 0; i < gvcheck.rows.length; i++) {

var inputs = gvcheck.rows[i].getElementsByTagName('input');

inputs[0].checked = true;

}

}
}

Enjoy and Keep Coding.
Posted by StepCoder Team 7/1/2014 12:12:59 PM
Post your answer
Preview
Sign in to your account
Your Email : 
Password :   
Forgot your password
Don't have StepCoder account ?
Create a new account
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
Answer these questions! If you know the answer.