本例包括以下控件的相关示例:
Button,ImageButton,TextBox,
DropDownList,CheckBox,RadioButton
的客户端及服务器端的禁用和启用
以及
LinkButton,HyperLink 的服务器端禁用和启用
和
借助于父控件如td等 来实现
LinkButton,HyperLink 的客户端禁用和启用
----------------------------------------
Button,ImageButton,TextBox,
DropDownList,CheckBox,RadioButton
的客户端及服务器端的禁用和启用
------------------------------------
服务器端 相关代码如下:
//服务器端启用
protected void Button2_Click(object sender, EventArgs e)
{
Button1.Attributes.Remove("disabled");
ImageButton1.Attributes.Remove("disabled");
TextBox1.Attributes.Remove("disabled");
DropDownList1.Attributes.Remove("disabled");
CheckBox1.Attributes.Remove("disabled");
RadioButton1.Attributes.Remove("disabled");
}
//服务器端禁用
protected void Button4_Click(object sender, EventArgs e)
{
Button1.Attributes["disabled"] = "true";
ImageButton1.Attributes["disabled"] = "true";
TextBox1.Attributes["disabled"] = "true";
DropDownList1.Attributes["disabled"] = "true";
CheckBox1.Attributes["disabled"] = "true";
RadioButton1.Attributes["disabled"] = "true";
}
客户端 相关代码如下:
<script language="javascript" type="text/javascript">
//客户端禁用
function ControlDisabled()
{
document.all.Button1.disabled = true;
document.all.ImageButton1.disabled = true;
document.all.TextBox1.disabled = true;
document.all.DropDownList1.disabled = true;
document.all.CheckBox1.disabled = true;
document.all.RadioButton1.disabled = true;
}
//客户端启用
function ControlEnabled()
{
document.all.Button1.disabled = false;
document.all.ImageButton1.disabled = false;
document.all.TextBox1.disabled = false;
document.all.DropDownList1.disabled = false;
document.all.CheckBox1.disabled = false;
document.all.RadioButton1.disabled = false;
}
</script>
-----------------------------
LinkButton,HyperLink 的服务器端 禁用与启用
(不支持对LinkButton的 OnClientClick 事件的禁用)
-------------------------------------------------
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="LinkButton1_Click" >
LinkButton</asp:LinkButton>
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.freeliver.cn" Target="_blank" >
HyperLink</asp:HyperLink>
<br />
服务器端代码:
//LinkButton,HyperLink 服务器端启用
protected void Button2_Click(object sender, EventArgs e)
{
LinkButton1.Enabled = true;
HyperLink1.Enabled = true;
}
//LinkButton,HyperLink 服务器端禁用
protected void Button4_Click(object sender, EventArgs e)
{
LinkButton1.Enabled = false;
HyperLink1.Enabled = false;
}
-----------------------
借助于父控件如td等
来实现 LinkButton,HyperLink 的客户端禁用和启用
--------------------------
<table>
<tr>
<td id="tdLinkButton" onclick="return tdLinkButtonOnClick();">
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="LinkButton1_Click" >
LinkButton</asp:LinkButton>
</td>
<td id="tdHyperLink" onclick="return tdHyperLinkOnClick();">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://www.freeliver.cn" Target="_blank" >
HyperLink</asp:HyperLink>
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
//LinkButton,HyperLink 客户端禁用
function ControlDisabled()
{
document.all.LinkButton1.disabled = true;
document.all.HyperLink1.disabled = true;
}
//LinkButton,HyperLink 客户端启用
function ControlEnabled()
{
document.all.LinkButton1.disabled = false;
document.all.HyperLink1.disabled = false;
}
//tdLinkButton的onclick事件
//如果LinkButton1的disabled==true
//则不响应相关事件
function tdLinkButtonOnClick()
{
if(document.all.LinkButton1.disabled)
{
return false;
}
else
{
return true;
}
}
//tdHyperLink的onclick事件
//如果HyperLink1的disabled==true
//则不响应相关事件
function tdHyperLinkOnClick()
{
if(document.all.HyperLink1.disabled)
{
return false;
}
else
{
return true;
}
}
</script>