2

我有以下代码。

我想要的是当 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" 属性,但是,这导致了完整的回发(这里也描述了问题:下拉列表(在更新面板中)导致完整的回发!

我错过了什么?

4

2 回答 2

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>  
于 2013-09-04T17:29:19.763 回答
1

可能您没有OnSelectedIndexChanged在标记中设置事件,如上所示。

您应该设置三个属性:OnSelectedIndexChanged, AutoPostback&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...
      }
}
于 2013-09-05T02:08:57.330 回答