我为了往服务器传值用autopostback,我已经把dropdownlist放到updatapanel里面了 但是页面还是刷新 为什么 代码如下
前台大概这样的
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="zc.aspx.cs" Inherits="DtCms.Web.Aspx.zc" EnableEventValidation="false" %><%@ Register TagPrefix="DtContorl" Namespace="DtCms.Web.UI" Assembly="DtCms.Web.UI" %><!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"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title><%= SiteConfig.WebName %></title><!-- ===== css ===== --></head><body onLoad="init()"> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager><div><td width="200px"></td><td width="130px" align="right">籍贯:</td><td width="130px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="ddlProvince" runat="server" onselectedindexchanged="ddlProvince_SelectedIndexChanged1" AutoPostBack="true"> </asp:DropDownList> <asp:DropDownList ID="ddlCity" runat="server"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> </td></div> </form></body></html>
protected void ddlProvince_SelectedIndexChanged1(object sender, EventArgs e) { ddlCity.DataSource = bll.GetCity(ddlProvince.SelectedValue.ToString()).DefaultView;//根据页面的返回值传递信息绑定城市信息 ddlCity.DataTextField = bll.GetCity(ddlProvince.SelectedValue.ToString()).Columns[0].ToString(); ddlCity.DataBind(); } <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <table> <tr> <td width="130px" align="right"> 籍贯: </td> <td width="130px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="ddlProvince" runat="server" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged1" AutoPostBack="true"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlCity" runat="server"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </table> </div> </form>
[解决办法]
<asp:ScriptManager runat="server"> </asp:ScriptManager> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged"> <asp:ListItem Text="aaaa" Value="1"></asp:ListItem> <asp:ListItem Text="bbb" Value="2"></asp:ListItem> <asp:ListItem Text="ccc" Value="3"></asp:ListItem> <asp:ListItem Text="ddd" Value="4"></asp:ListItem> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlTest" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel>
[解决办法]
updatepanel 要指定控件及控件的事件
<triggers>标签 好像是这个功能
[解决办法]
也许楼上的正确