Simple Example of ASP. NET Ajax

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.