dropdownlist的SelectedIndexChanged 无响应
搜索过无数的帖子,大概看下来无非就是 !IsPostBack 和 AutoPostBack 问题,但是未果,还是请大家指点:
<asp:DropDownList ID="District" runat="server" AutoPostBack="True"
DataTextField="District"
DataValueField="District"
onselectedindexchanged="District_SelectedIndexChanged">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
</asp:DropDownList>
protected void District_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("111");
}
Page_Load 中已经做判断 !this.IsPostBack
做了断点,发现事件没有触发,于是又添加了一个Button1
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("222");
}
测试发现,如果我先改变dropdownlist,然后点击button,111和222会同时显示,也就是说只有点击button1以后才触发了District_SelectedIndexChanged....
我想哀嚎一声:为啥?
------解决方案--------------------测试过了 完全没有问题!~。。
------解决方案--------------------button和dropdownlist在一个布局里面吗。 你重新添加一个试试,
------解决方案--------------------按照你上面给的局部代码,应该是没有任何问题的.
我也测试了一下
------解决方案--------------------
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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:DropDownList ID="District" runat="server" AutoPostBack="True" DataTextField="District"
DataValueField="District" OnSelectedIndexChanged="District_SelectedIndexChanged">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>