【问题标题】:ASP.NET Update Panel Updates only OnceASP.NET 更新面板仅更新一次
【发布时间】:2011-10-16 21:12:02
【问题描述】:

您好,我有一个这样的更新面板

<asp:UpdatePanel ID="Updatepanel1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="RadioButtons1" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="DropDown1" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="DropDown2" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="DropDown3" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <asp:Label runat="server" Text="LabelToUpdate"></asp:Label>
    </ContentTemplate>

</asp:UpdatePanel>

我想在每次上述触发器之一发生时更新标签。

我第一次触发它时一切正常。但在那之后,即使我改变了任何东西,也没有更多的更新(就像所有 Control 的 AutoPostBack 在第一次 Partial Post 回来后被设置为 false,所以当我第二次更改选择时没有任何反应)。

非常感谢任何帮助

谢谢

【问题讨论】:

  • “所有触发器 AutoPostBack 都设置为 false”是什么意思?
  • 嗨,很抱歉让您感到困惑。我的意思是页面上不会再发回任何内容。当我更改下拉列表的值并且单选按钮列出时,没有任何反应。就好像他们不再做回发
  • 您是否在回发时对这些控件进行数据绑定?您应该将其嵌入到if(!Page.IsPostBack)-check 中。这些控件是动态创建的吗?您知道每次回发时 control-id 必须相同才能触发事件吗?您是否已调试以查看是否处理了 page_load?您在页面上看到任何 javascript 错误吗?
  • 1- 回发数据绑定:否 2- 将其嵌入到 if(!Page.IsPostBack) 中:我使用此检查来设置默认值。我没明白你的意思。 3- 这些控件是动态创建的吗?:没有。但是我在回发上创建了其他控件。 (我在更新面板中创建其他标签) 4- 每次回发的控制 ID 必须相同:相同的是,我不会对触发更新面板的控件进行任何更改。 5-page_load 被处理了吗?它不被处理。当我更改选择时没有任何反应 6- 您是否在页面上看到任何 javascript 错误:否- 我没有使用任何 javascript
  • 也许你应该发布实际代码

标签: c# asp.net updatepanel partial-postback


【解决方案1】:

复制并粘贴这个 .. 工作正常 :)

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:RadioButtonList ID="RadioButtons1" runat="server" AutoPostBack="true">
        <asp:ListItem Text="1" Selected="True"></asp:ListItem>
        <asp:ListItem Text="2"></asp:ListItem>
        <asp:ListItem Text="3"></asp:ListItem>
        <asp:ListItem Text="4"></asp:ListItem>
    </asp:RadioButtonList>
    <br />
    <asp:DropDownList ID="DropDown1" runat="server" AutoPostBack="true">
        <asp:ListItem Text="1" Selected="True"></asp:ListItem>
        <asp:ListItem Text="2"></asp:ListItem>
        <asp:ListItem Text="3"></asp:ListItem>
        <asp:ListItem Text="4"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <asp:DropDownList ID="DropDown2" runat="server" AutoPostBack="true">
        <asp:ListItem Text="1" Selected="True"></asp:ListItem>
        <asp:ListItem Text="2"></asp:ListItem>
        <asp:ListItem Text="3"></asp:ListItem>
        <asp:ListItem Text="4"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <asp:DropDownList ID="DropDown3" runat="server" AutoPostBack="true">
        <asp:ListItem Text="1" Selected="True"></asp:ListItem>
        <asp:ListItem Text="2"></asp:ListItem>
        <asp:ListItem Text="3"></asp:ListItem>
        <asp:ListItem Text="4"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <asp:UpdatePanel ID="Updatepanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="RadioButtons1" />
            <asp:AsyncPostBackTrigger ControlID="DropDown1" />
            <asp:AsyncPostBackTrigger ControlID="DropDown2" />
            <asp:AsyncPostBackTrigger ControlID="DropDown3" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="LabelToUpdate"><%= "rad: " + RadioButtons1.SelectedItem.Text + "<br />" + "drop1: " + DropDown1.SelectedItem.Text + "<br />" + "drop2: " + DropDown2.SelectedItem.Text + "<br />" + "drop3: " + DropDown3.SelectedItem.Text %></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多