Click here to Skip to main content
16,020,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write javascript code for content place holder in master pages? how to acess those controls in java script?

Actually i have a master page(ex master1.master) and in this i have a content place holder with two controls like checkbox and a textbox.


My reqirement is when i check a checkbox the textbox must disable and when unchecked ,textbox must enable.


so, i need a java script code to do this.
Posted

1 solution

Hi,

Its very simple. Follow the steps which will solve ur problem.

Step1: In ur master page write the following javascript function:


function EnableDisableTextBox(CheckBoxClientId,TextBoxClientId)
{
var chkBox = document.getElementById(CheckBoxClientId);
if(chkBox && document.getElementById(TextBoxClientId))
{
if(chkBox.checked)
document.getElementById(TextBoxClientId).disabled = true;
else
document.getElementById(TextBoxClientId).disabled = false;
}
return false;
}

Step:2 In the CodeBehind of ur MasterPage write the following code on page load event.


checkbox.Attributes.Add("onclick","EnableDisableTextBox('" + checkbox.ClientID + "','" + textBox.ClientID + "')");

Try to execute and check. Even while click of the checkbox it will not postback also. The enable and disable will be done at client level. Try this:thumbsup:
 
Share this answer
 

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