一、AutoPostBack刷新页面
DropDownList使用AutoPostBack常遇见两个问题:
DropDownList点击不触发事件
需要加上AutoPostBack=<font style="color:rgb(128, 0, 0);">"true"</font>这个属性
加入AutoPostBack后全局刷新
asp中使用UpdatePanel
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"><ContentTemplate><asp:DropDownList ID="ddlcountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged"></asp:DropDownList></ContentTemplate></asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server"><ContentTemplate><asp:DropDownList ID="ddpostway" runat="server"></asp:DropDownList></ContentTemplate></asp:UpdatePanel>
具体:
- 哪里使用了AutoPostBack哪里加入UpdatePanel
- 哪里需要联动更新的使用UpdatePanel
二、onchange事件
functionselectDpList(dp) {varsIndex=dp.selectedIndex;//返回选中是第几项 0,1....varsText=dp.options[dp.selectedIndex].text;//返回选中的文本--文本1,文本2 ...varsValue=dp.value;//返回选中的文本--v1,v2 ...}
<asp:DropDownListrunat="server"CssClass="productType"ID="dp_ProductTag"Width="153px"onchange="JavaScript:selectDpList(this)"><asp:ListItemText="文本1"Value="1"></asp:ListItem><asp:ListItemText="文本2"Value="2"></asp:ListItem><asp:ListItemText="文本3"Value="2"></asp:ListItem></asp:DropDownList>
若有收获,就点个赞吧
