Javascript In Masterpage


This trick shows you how to make JavaScript work in Master Page
When you use JavaScript for client side validation in .aspx form, it works well. But as soon as you apply the same JavaScript code to validate form having Master Page, it gives you error like Object required or anything else. Many people thinks that why this is happening and can’t find any reason and any solution to solve this. But there is a trick to solve this problem. First make a simple form without using Master Page and use JavaScript to validate it. You found o errors and code will run smoothly. Now make a new form having Master Page. Now modify the same JavaScript to make it work.
JavaScript used in form without Master Page.

document.getElementById(‘txtName’).value;

Here txtName is the ID of the textbox.
Now just modify the above code to make it work in the form having Master Page.

document.getElementById(“<%= txtName.ClientID %>”).value;

And done problem is solved. Remember C , ID is in caps in ClientID.
Comments……!

Comments

Popular posts from this blog

Get Query String Values With Javascript

Change Css Class of li in ul onclick

Change Text Color with Javascript