Search code examples
asp.netdrop-down-menuupdatepanel

update panel has does not work anymore


Im not sure what's happening here. But I had an update panel on my page which was populating a City dropdown on the State dropdown selecteditem event. It was working, for some reason now it is not. It doesn't even pop up the message box I put as the first line of code in the event.

Here is the markup;

<!-- State dropdown selector area -->
        <asp:DropDownList ID="ddlState"  runat="server"
                          AppendDataBoundItems="True" CssClass="dropdowns"
                          BorderColor="Black"
                          BorderStyle="Solid" BorderWidth="2px" TabIndex="7" 
                          DataSourceID="EntityDataSource1" DataTextField="Name"
                          DataValueField="Id" ToolTip="Select a state here" AutoPostBack="True">
            <asp:ListItem Value="" Text="Select a state"/>
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=enerteckEntities"
             DefaultContainerName="enerteckEntities" EnableFlattening="False" EntitySetName="states"
             Select="it.[Name], it.[Id]">
        </asp:EntityDataSource>
        <asp:RequiredFieldValidator ID="rfvState" runat="server" 
                                    ErrorMessage="Please select a state from the dropdown list"
                                    Display="Dynamic" ControlToValidate="ddlState" 
                                    ForeColor="#FF3300">
        </asp:RequiredFieldValidator>
        <!-- End of State dropdown selector area -->
    <br /><br />
    <asp:UpdatePanel ID="updtPanelCity" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="ddlCity"  runat="server"
                              AppendDataBoundItems="True" CssClass="dropdowns"
                              BorderColor="Black"
                              BorderStyle="Solid" BorderWidth="2px" TabIndex="8" 
                               ToolTip="Select a city here" AutoPostBack="True">
                <asp:ListItem Value="" Text="Select a city"/>
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="rfvCity" runat="server" 
                                        ErrorMessage="Please select a city from the dropdown list"
                                        Display="Dynamic" ControlToValidate="ddlCity" 
                                        ForeColor="#FF3300">
            </asp:RequiredFieldValidator>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlState" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>

Here is the code behind;

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

End Sub

Protected Sub ddlState_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlState.SelectedIndexChanged
    MsgBox("are you actually working")
    If IsPostBack Then
        ddlCity.Items.Clear()
        Dim context As New enerteckEntities()

        'Dim query = context.DistinctCityFromZiptax(Convert.ToInt16(ddlState.SelectedValue))
        Dim query = From c In context.ziptaxes Where c.StateID = ddlState.SelectedValue Order By c.City Select c.City, c.ZipTaxId
        ddlCity.DataSource = query.Distinct().ToList()
        ddlCity.DataValueField = "ziptaxid"
        ddlCity.DataTextField = "City"
        ddlCity.DataBind()
    End If

End Sub

I need another set of eyes on this problem.

EDIT: Here is whats in the scriptmanager

 <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <%--Framework scripts--%>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="jquery.ui.combined" />
        <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
        <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
        <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
        <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
        <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
        <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
        <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
        <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
        <asp:ScriptReference Name="WebFormsBundle" />
        <%--Site scripts--%>

    </Scripts>
</asp:ScriptManager>

Solution

  • 1 You can add UpdateMode property on your UpdatePanel. And set to Conditional

    <asp:UpdatePanel ID="updtPanelCity"
                                     UpdateMode="Conditional"
                                     runat="server">
    
    ....
    

    2 And place your ddl in update panel

       <ContentTemplate>
          ....
         <asp:DropDownList ID="ddlState"  runat="server"
                              AppendDataBoundItems="True" CssClass="dropdowns"
                              BorderColor="Black"
                              BorderStyle="Solid" BorderWidth="2px" TabIndex="7" 
                              DataSourceID="EntityDataSource1" DataTextField="Name"
                              DataValueField="Id" ToolTip="Select a state here" AutoPostBack="True">
                <asp:ListItem Value="" Text="Select a state"/>
            </asp:DropDownList>
     </ContentTemplate>
    

    3 And add OnSelectedIndexChanged="" on your dllState