日期:2014-05-17  浏览次数:20505 次

我为了往服务器传值用autopostback,我已经把dropdownlist放到updatapanel里面了 但是页面还是刷新 为什么 代码如下
前台大概这样的
HTML code

 <%@ 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>


后台大概这样的
C# code

 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();
        } 



------解决方案--------------------
UpdatePanel要放在一个完整的标签中才会不刷新,你用UpdatePanel把table包住
------解决方案--------------------
没用的dropdownlist 压根就不支持updatepannel方式的无刷新
------解决方案--------------------
C# code

<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>