两个dropdownlist 的 postback 都发生了!bug还是viewstate 问题?
下面是测试网页,
跟踪网页的执行你会发现第二次选dropdownlist1的时候,dropdownlist1的postback event发生了,但是同时dropdownlist3的postback event也发生了,可是实际上这个postback是list1发生的,和list3无关的,至少在client端时这样的。
.net 2.0, 1.1都测试了,一样地结果。
不知道这算是bug,还是viewstate的问题(by design?)。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("list2 item1"));
DropDownList2.Items.Add(new ListItem("list2 item2"));
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add(new ListItem("list3 item1"));
DropDownList3.Items.Add(new ListItem("list3 item2"));
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Server.Transfer("htmlpage.htm"); // 建一个空网页即可
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>list1 item1</asp:ListItem>
<asp:ListItem>list1 item2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
</asp:DropDownList></div>
</form>
</body>
</html>
测试方法:依次选dropdownlist, dropdownlist2 和 dropdownlist3,你会自动转到下一个html页,这时候点 IE 工具栏中的后退按钮,回到选择页,再选dropdownlist1中的一项,这时候你会马上重新转到html页。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("list2 item1"));
DropDownList2.Items.Add(new ListItem("list2 item2"));
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add(new ListItem("list3 item1"));
DropDownList3.Items.Add(new ListItem("list3 item2"));
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Server.Transfer("htmlpage.htm"); // 建一个空网页即可
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>list1 item1</asp:ListItem>
<asp:ListItem>list1 item2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
</asp:DropDownList></div>
</form>
</body>
</html>
跟踪网页的执行你会发现第二次选dropdownlist1的时候,dropdownlist1的postback event发生了,但是同时dropdownlist3的postback event也发生了,可是实际上这个postback是list1发生的,和list3无关的,至少在client端时这样的。
.net 2.0, 1.1都测试了,一样地结果。
不知道这算是bug,还是viewstate的问题(by design?)。