使用dropdownlist能實現不重新整理頁面的效果具體例子
至少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.csusing 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; }}