如何在母版页中为内容占位符编写JavaScript代码?如何在Java脚本中访问这些控件? [英] How to write javascript code for content place holder in master pages?& how to acess those controls in java script?

查看:81
本文介绍了如何在母版页中为内容占位符编写JavaScript代码?如何在Java脚本中访问这些控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在母版页中为内容占位符编写javascript代码?如何在Java脚本中访问这些控件?

实际上,我有一个母版页(例如master1.master),并且在其中有一个内容占位符,其中包含两个控件,如复选框和文本框.


我的要求是,当我选中一个复选框时,必须禁用文本框,而当未选中时,必须启用文本框.


因此,我需要一个Java脚本代码来执行此操作.

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.

推荐答案



它非常简单.请按照将解决您的问题的步骤进行操作.

第一步:在您的母版页中,编写以下javascript函数:


函数EnableDisableTextBox(CheckBoxClientId,TextBoxClientId)
{
var chkBox = document.getElementById(CheckBoxClientId);
if(chkBox& document.getElementById(TextBoxClientId))
{
if(chkBox.checked)
document.getElementById(TextBoxClientId).disabled = true;
其他
document.getElementById(TextBoxClientId).disabled = false;
}
返回false;
}

步骤2:在您的MasterPage的CodeBehind中,在页面加载事件中编写以下代码.


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

尝试执行并检查.即使单击复选框,它也不会回发.启用和禁用将在客户端级别完成.试试这个:thumbsup:
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:


这篇关于如何在母版页中为内容占位符编写JavaScript代码?如何在Java脚本中访问这些控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆