更新面板不起作用

时间:2014-06-10 06:55:56

标签: asp.net asp.net-ajax updatepanel

我试图获取下拉列表的值并将其插入更新面板内的标签,如下所示:

    <asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><br />
            <asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
            <asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
            <asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
            <asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>

在代码背后我有

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblEpisode.Text = DropDownList1.SelectedValue.ToString();
    }

但我不知道为什么它不更新标签!!标签的文字保持不变!!!谁能发现问题?

3 个答案:

答案 0 :(得分:0)

尝试删除触发器以获得类似的内容

<br />
<asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
        <asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
        <asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
        <asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
    </ContentTemplate>

答案 1 :(得分:0)

您必须将下拉列表放入现有的更新面板中......

答案 2 :(得分:0)

您需要在活动中调用更新面板的Update()方法,如下所示。

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    lblEpisode.Text = DropDownList1.SelectedValue.ToString();
    udpTutorialDropDown.Update();
}

一切顺利!

<强>更新

您必须在下拉列表中添加AutoPostBack="true"属性。而且,忽略我以前的指示。即调用更新面板的Update()方法。只有在您拥有UpdateMode="Conditional"

时才需要这样做

这应该有效:)