我有以下代码。
我想要的是当ddlProvince下拉列表被更改时,抛出事件SelectedIndexChanged,但是永远不会访问该方法。
<asp:UpdatePanel ID="pnlCountries" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<tr>
<td><asp:Literal ID="Literal37" Text="<%$Resources:glossary,country %>" runat="server"/></td>
<td>
<asp:DropDownList ID="ddlCountries" CssClass="textbox" runat="server">
</asp:DropDownList>
<br />
<cc1:cascadingdropdown ID="cddCountries" runat="server" Category="Country" Enabled="True" LoadingText="<%$Resources:Glossary,loading %>" PromptText="<%$Resources:Glossary,country_choose %>"
ServiceMethod="GetCountries" TargetControlID="ddlCountries">
</cc1:cascadingdropdown>
<asp:RequiredFieldValidator CssClass="errortext" Text="<%$Resources:Glossary,required %>" SetFocusOnError="true" ID="rfvcboScenario" runat="server" InitialValue="" ControlToValidate="ddlCountries" Display="Dynamic" />
</td>
</tr>
<tr>
<td><strong><asp:Literal ID="Literal9" Text="<%$Resources:Glossary,province %>" runat="server" /> *</strong></td>
<td>
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator CssClass="errortext" Text="<%$Resources:Glossary,required %>" SetFocusOnError="true" ID="RequiredFieldValidator1" runat="server" InitialValue="" ControlToValidate="ddlProvince" Display="Dynamic" />
<cc1:CascadingDropDown ID="cddProvince" runat="server" TargetControlID="ddlProvince" ParentControlID="ddlCountries"
Category="Province" LoadingText="<%$Resources:Glossary,loading %>" prompttext="<%$Resources:Glossary,province_select %>" ServiceMethod="GetProvincesForCountry" >
</cc1:CascadingDropDown>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
目前此代码行永远不会被命中:
Protected Sub ddlProvince_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProvince.SelectedIndexChanged
ReportError("ddlProvince_SelectedIndexChanged", "")
End Sub
更新: 之前我在ddlProvince控件上有了Autopostback =“true”属性,但这导致了一个完整的回发(问题也在这里描述:Drop Down List (in Update Panel) causing FULL PostBack!)
我错过了什么?
答案 0 :(得分:2)
修改强>
您需要为下拉列表设置AutoPostBack="true"
。改变这个:
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server">
</asp:DropDownList>
到此:
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server" AutoPostBack="true" >
</asp:DropDownList>
答案 1 :(得分:1)
可能您没有在标记中设置OnSelectedIndexChanged
事件,如上所示。
您应该设置三个属性:OnSelectedIndexChanged
,AutoPostback
&amp; EnableViewState
<asp:DropDownList ID="ddlProvince" runat="server"
AutoPostBack="true" EnableViewState="true"
OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
如果你绑定了page_Load
事件中的下拉列表,请将其置于!IsPostback
条件检查中:
protected void page_Load ( object sender, EventArgs e )
{
if(!IsPostBack)
{
//DropDownList data bind and all...
}
}