更新面板已不再起作用

时间:2012-09-11 18:00:50

标签: asp.net drop-down-menu updatepanel

我不确定这里发生了什么。但是我的页面上有一个更新面板,它正在填写State下拉列表中的一个City下拉列表。 它工作,由于某种原因,现在它不是。它甚至没有弹出我作为事件中第一行代码放置的消息框。

这是标记;

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

这是背后的代码;

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

我需要另外一套眼睛解决这个问题。

编辑: 以下是剧本管理员的内容

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

1 个答案:

答案 0 :(得分:0)

1您可以在UpdatePanel上添加UpdateMode属性。并设置为条件

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

....

2并将您的ddl放在更新面板

   <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并在你的dllState上添加OnSelectedIndexChanged=""