This example includes examples of the following controls:
Button, imagebutton, Textbox,
Dropdownlist, checkbox, radiobutton
Disable and enable the client and server
And
Linkbutton, Which is disabled and enabled by the hyperlink server.
And
Implemented by using parent controls such as TD
Linkbutton, Which is disabled and enabled by the hyperlink client.
----------------------------------------
Button, imagebutton, Textbox,
Dropdownlist, checkbox, radiobutton
Disable and enable the client and server
------------------------------------
Server-relatedCodeAs follows:
// Enable on the server
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 ");
}
// Disable the server
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 ";
}
The client-side code is as follows:
<Script language = "JavaScript" type = "text/JavaScript">
// Disable the client
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;
}
// Enable the client
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, Which is disabled and enabled by the hyperlink server.
(Disabling the onclientclick event of linkbutton is not supported)
-------------------------------------------------
<Asp: linkbutton id = "linkbutton1" runat = "server"
Onclick = "linkbutton#click">
Linkbutton </ASP: linkbutton>
<Br/>
<Asp: hyperlink id = "hyperlink1" runat = "server" navigateurl = "http://www.freeliver.cn" target = "_ blank">
Hyperlink </ASP: hyperlink>
<Br/>
Server code:
// Linkbutton, enabled on the hyperlink Server
Protected void button2_click (Object sender, eventargs E)
{
Linkbutton1.enabled = true;
Hyperlink1.enabled = true;
}
// Linkbutton, Which is disabled on the hyperlink Server
Protected void button4_click (Object sender, eventargs E)
{
Linkbutton1.enabled = false;
Hyperlink1.enabled = false;
}
-----------------------
With the help of parent controls such as TD
To disable and enable the linkbutton and hyperlink client.
--------------------------
<Table>
<Tr>
<TD id = "tdlinkbutton" onclick = "Return tdlinkbuttononclick ();">
<Asp: linkbutton id = "linkbutton1" runat = "server"
Onclick = "linkbutton#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, Which is disabled by the hyperlink Client
Function controldisabled ()
{
Document. All. linkbutton1.disabled = true;
Document. All. hyperlink1.disabled = true;
}
// Linkbutton, Which is enabled on the hyperlink Client
Function controlenabled ()
{
Document. All. linkbutton1.disabled = false;
Document. All. hyperlink1.disabled = false;
}
// Onclick event of tdlinkbutton
// If the disabled of linkbutton1 is = true
// Does not respond to related events
Function tdlinkbuttononclick ()
{
If (document. All. linkbutton1.disabled)
{
Return false;
}
Else
{
Return true;
}
}
// Tdhyperlink onclick event
// If the disabled of hyperlink1 is = true
// Does not respond to related events
Function tdhyperlinkonclick ()
{
If (document. All. hyperlink1.disabled)
{
Return false;
}
Else
{
Return true;
}
}
</SCRIPT>