积极答复者
为什么用了updateplan还是会有刷新,请看源码

问题
-
<asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="ddlType" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlType_SelectedIndexChanged">
</asp:DropDownList><asp:UpdatePanel ID="uppItem" runat="server"
UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="ddlItem" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="ddlType" /></Triggers>
</asp:UpdatePanel>为什么我改变了第一个下拉菜单的值以后,整个页面还是会刷新呢?为何?
答案
-
呵呵,web控件,即可以放在updatepanel之内,也可以放在它之外的。放在外面,必须指定触发器,而都放在内面,则不用指定触发器。
哦,没注意!我测了一下,没有问题。贴出我的测试代码:<!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>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>public partial class DD : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList1.SelectedValue = this.DropDownList2.SelectedValue;
}
}- 已标记为答案 BU XI - MSFTModerator 2011年3月14日 7:28
全部回复
-
UpdatePanel没有包裹ddlType。
<asp:UpdatePanel ID="uppItem" runat="server"
UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="ddlType" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlType_SelectedIndexChanged">
</asp:DropDownList><asp:DropDownList ID="ddlItem" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="ddlType" /></Triggers>
</asp:UpdatePanel> -
呵呵,web控件,即可以放在updatepanel之内,也可以放在它之外的。放在外面,必须指定触发器,而都放在内面,则不用指定触发器。
哦,没注意!我测了一下,没有问题。贴出我的测试代码:<!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>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>public partial class DD : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList1.SelectedValue = this.DropDownList2.SelectedValue;
}
}- 已标记为答案 BU XI - MSFTModerator 2011年3月14日 7:28