Example 1: simple and non-Refresh linkage of dropdownlist
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default2.aspx. cs" inherits = "default2" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT runat = "server">
Protected void dplfood_selectedindexchanged (Object sender, eventargs E)
{
If (dplfood. selectedvalue = "0 ")
{
Dpllist. Items. Clear ();
Listitem item = new listitem ("cabbage", "0 ");
Dpllist. Items. Add (item );
Item = new listitem ("Luo Wei", "1 ");
Dpllist. Items. Add (item );
}
If (dplfood. selectedvalue = "1 ")
{
Dpllist. Items. Clear ();
Listitem item = new listitem ("apple", "0 ");
Dpllist. Items. Add (item );
Item = new listitem ("plum", "1 ");
Dpllist. Items. Add (item );
Item = new listitem ("Peach", "2 ");
Dpllist. Items. Add (item );
}
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "script" runat = "server"> </ASP: scriptmanager>
<Asp: updatepanel id = "updatepanel" runat = "server">
<Contenttemplate>
<Asp: dropdownlist id = "dplfood" runat = "server" autopostback = "true" onselectedindexchanged = "dplfood_selectedindexchanged">
<Asp: listitem text = "Vegetables" value = "0"> </ASP: listitem>
<Asp: listitem text = "Fruit" value = "1"> </ASP: listitem>
</ASP: dropdownlist>
<Asp: dropdownlist id = "dpllist" runat = "server">
</ASP: dropdownlist>
</Contenttemplate>
</ASP: updatepanel>
</Div>
</Form>
</Body>
</Html>
Example 2: change the background color of a calendar
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<SCRIPT runat = "server">
Void dropdownselection_change (Object sender, eventargs E)
{
Calendar1.daystyle. backcolor =
System. Drawing. color. fromname (colorlist. selecteditem. value );
}
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> scriptmanager example </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "scriptmanager1"
Runat = "server">
</ASP: scriptmanager>
<Asp: updatepanel id = "updatepanel1"
Runat = "server">
<Contenttemplate>
<Asp: Calendar id = "calendar1"
Showtitle = "true"
Runat = "server"/>
<Div>
Background:
<Br/>
<Asp: dropdownlist id = "colorlist"
Autopostback = "true"
Onselectedindexchanged = "dropdownselection_change"
Runat = "server">
<Asp: listitem selected = "true" value = "white">
White </ASP: listitem>
<Asp: listitem value = "Silver">
Silver </ASP: listitem>
<Asp: listitem value = "darkgray">
Dark gray </ASP: listitem>
<Asp: listitem value = "khaki">
Khaki </ASP: listitem>
<Asp: listitem value = "darkkhaki"> d
Ark khaki </ASP: listitem>
</ASP: dropdownlist>
</Div>
</Contenttemplate>
</ASP: updatepanel>
<Br/>
</Div>
</Form>
</Body>
</Html>