2

I have the following code.

What i want is when the ddlProvince dropdown is changed, to throw the event SelectedIndexChanged, however that method is never accessed.

<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>

Currently this codeline is never hit:

Protected Sub ddlProvince_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProvince.SelectedIndexChanged
    ReportError("ddlProvince_SelectedIndexChanged", "")
End Sub

update: previously I had the Autopostback="true" attribute on the ddlProvince control, however, that caused a full postback (issue also described here: Drop Down List (in Update Panel) causing FULL PostBack!)

What am I missing?

Community
  • 1
  • 1
Adam
  • 6,041
  • 36
  • 120
  • 208
  • 1
    Probably you found it already- you need to set `AutoPostback="true"` of ddlProvince, then the AsyncPostBack works fine. You need to keep the AsyncPostBackTrigger as well. – afzalulh Sep 04 '13 at 19:32
  • This should be your answer :) – Adam Sep 04 '13 at 21:31

2 Answers2

2

EDIT: You need to set AutoPostBack="true" for the dropdownlist. Change this:

<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server">
        </asp:DropDownList>

to this:

<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server" AutoPostBack="true" >
        </asp:DropDownList>  
afzalulh
  • 7,925
  • 2
  • 26
  • 37
  • 1
    I thought so too, but then I experienced this issue: http://stackoverflow.com/questions/2138565/drop-down-list-in-update-panel-causing-full-postback – Adam Sep 04 '13 at 17:35
  • Isn't the event already attached via this line: Protected Sub ddlProvince_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProvince.SelectedIndexChanged I also tried doing it your way and removed the 'Handles' part but still no luck... – Adam Sep 04 '13 at 18:07
  • thank youuuuuuuu i have started with auto post back but it acted wired but your post made try again and i understood what i did wrong. – Liran Oct 07 '13 at 16:02
1

Possibly you haven't set the OnSelectedIndexChanged event in the Markup as seen above.

Three properties you should set: OnSelectedIndexChanged, AutoPostback & EnableViewState

<asp:DropDownList ID="ddlProvince" runat="server" 
     AutoPostBack="true" EnableViewState="true"
     OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">                
</asp:DropDownList>

Incase you are binding your dropdownlist in page_Load event, place it inside !IsPostback condition check:

protected void page_Load ( object sender, EventArgs e )
{
     if(!IsPostBack)
     {
            //DropDownList data bind and all...
      }
}
R.C
  • 10,417
  • 2
  • 35
  • 48