01.
using
System;
02.
using
System.Collections;
03.
using
System.Configuration;
04.
using
System.Data;
05.
using
System.Linq;
06.
using
System.Web;
07.
using
System.Web.Security;
08.
using
System.Web.UI;
09.
using
System.Web.UI.HtmlControls;
10.
using
System.Web.UI.WebControls;
11.
using
System.Web.UI.WebControls.WebParts;
12.
using
System.Xml.Linq;
13.
14.
public
partial
class
MyPage : System.Web.UI.Page
15.
{
16.
protected
void
Page_Load(
object
sender, EventArgs e)
17.
{
18.
CheckBox1.Attributes.Add(
"OnClick"
,
"ck_frm()"
);
19.
AddJavaScript();
20.
}
21.
22.
private
void
AddJavaScript()
23.
{
24.
25.
System.Text.StringBuilder sb =
new
System.Text.StringBuilder();
26.
sb.Append(
"<script language=\"javascript\">\n"
);
27.
sb.Append(
"function ck_frm()\n"
);
28.
sb.Append(
"{\n"
);
29.
sb.Append(
"\t var ck = document.getElementById('"
);
30.
sb.Append(CheckBox1.ClientID);
31.
sb.Append(
"');\n"
);
32.
sb.Append(
"\t var dv = document.getElementById('"
);
33.
sb.Append(Panel1.ClientID);
34.
sb.Append(
"');\n\n"
);
35.
sb.Append(
"\t if (ck.checked == true)\n"
);
36.
sb.Append(
"\t {\n"
);
37.
sb.Append(
"\t\t dv.style.display = '';\n"
);
38.
sb.Append(
"\t }\n"
);
39.
sb.Append(
"\t else\n"
);
40.
sb.Append(
"\t {\n"
);
41.
sb.Append(
"\t\t dv.style.display = 'none';\n"
);
42.
sb.Append(
"\t }\n}\n"
);
43.
sb.Append(
"</script>\n\n"
);
44.
45.
46.
ClientScriptManager cs = Page.ClientScript;
47.
48.
if
(!cs.IsClientScriptBlockRegistered(
this
.GetType(),
"ck_frm"
))
49.
cs.RegisterClientScriptBlock(
this
.GetType(),
"ck_frm"
, sb.ToString(),
false
);
50.
}
51.
}