【问题标题】:Dynamically Loaded Existing Panel cause issue of PostBack动态加载的现有面板导致 PostBack 问题
【发布时间】:2014-12-04 07:36:20
【问题描述】:

首先查看下面的代码。

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test.aspx.vb" Inherits="BLL.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
    <div>
        <asp:Panel ID="pnlCustom" runat="server"></asp:Panel>
        <asp:Panel ID="pnlDiv1" runat="server">
            <asp:DropDownList ID="ddl_Status" runat="server"></asp:DropDownList>
        </asp:Panel>
        <asp:Panel ID="pnlDiv2" runat="server">
            <asp:DropDownList ID="ddlImg1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlImg1_SelectedIndexChanged"></asp:DropDownList>
        </asp:Panel>
        <asp:Panel ID="pnlDiv3" runat="server">
            <asp:DropDownList ID="ddlImg2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlImg2_SelectedIndexChanged"></asp:DropDownList>
        </asp:Panel>
    </div>
</form>
</body>
</html>

我想根据要求以不同的顺序隐藏和显示面板。我不想更改面板的内容。 pnlDiv1,pnlDiv2,pnlDiv3 将绑定在 pnlCustom 中。

现在,在 Page_Load 事件中,我将除“pnlCustom”之外的所有面板样式设置为“display:none”,并在“pnlCustom”中动态添加 pnlDiv1/pnlDiv2/pnlDiv3 并将其样式设置为“display:inline”。

在我的应用程序中,问题是如果我更改“ddlImg1”的值,页面将得到回发并重置所有值。这与“ddlImg2”相同。

注意:如果不是回发,值将绑定在 Page_Load 的下拉列表中。所以,任何人都可以解释什么是问题?

【问题讨论】:

  • 如果您在 ddlImg1 和 ddlImg2 上设置 AutoPostBack="false" 会怎样?这能解决你的问题吗?
  • 您在什么事件中将子面板插入“pnlCustom”?
  • 我在 Page_Load 事件中将孩子插入“pnlCustom”。如果我设置 autoPostBack="true" 然后整个页面重新加载,它不会加载“ddlStatus”的值..

标签: asp.net .net vb.net postback


【解决方案1】:

这可能是 ViewState 的问题。

以下链接可能对您有所帮助:

ASP.NET DropDownList not retaining selected item on postback

【讨论】:

    猜你喜欢
    • 2011-06-25
    • 1970-01-01
    • 2010-10-05
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多