至少VS2008 sp1 以上
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
//ASP.NET中使用UpdatePanel实现局部异步刷新
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="SelectProductType" AutoPostBack="True" OnSelectedIndexChanged="SelectProductTypeChange" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SelectProductType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
//后台下拉框选择改变触发事件
protected void SelectProductTypeChange(object sender, EventArgs e)
{
//
}
asp:ScriptManager 概述:
1, ScriptManager(脚本控制器)是asp.net ajax存在的基础.
2, 一个页面只允许有一个ScriptManager,并且放在其他ajax控件的前面.
3,ScriptManager掌管着客户端Ajax页的多有脚本,并在页面中注册Ajax类库,用来实现页面的局部更新和对Web服务的调用.
参考与:ScriptManager的简单用法
注:
1.ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果。其中的UpdatePanel就是设置页面中异 步局部更新区域,它必须依赖于ScriptManager存在,因为ScriptManger控件提供了客户端脚本生成与管理UpdatePanel的功能。
2.updatepanel 外有个 button 如果给它设置成AsyncPostBackTrigger 点button页面不刷新
方法二:
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Temp.aspx.cs" Inherits="Temp" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" style="width: 40px">
<asp:ListItem Value="1">aa</asp:ListItem>
<asp:ListItem Value="2">bb</asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
.aspx.cs
using System;
public partial class Temp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedValue;
}
}