【问题标题】:UpdatePanel and two content placeholder areas from a master pageUpdatePanel 和母版页中的两个内容占位符区域
【发布时间】:2011-04-15 12:29:54
【问题描述】:

我有一个“旧”的 ASP.NET 网站,我想稍微改进一下。我想做的一个领域是页面更新 - 目前,它始终是整页更新,但我想开始使用部分更新。

我希望能够为此使用 ASP.NET UpdatePanel - 但我有点不知道如何让它为我工作。

我有一个母版页,它定义了几个内容占位符 - 简化后看起来像这样:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="WebForms_Default" %>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>MyTitle</title>
</head>
<body>
   <form id="myForm" runat="server">
      <asp:ScriptManager ID="smgrMaster" runat="server" LoadScriptsBeforeUI="true">
         <Scripts>
            <asp:ScriptReference Path="~/Scripts/jquery-1.4.2.min.js" />
         </Scripts>
      </asp:ScriptManager>
      <asp:ContentPlaceHolder runat="server" ID="cphSearch" />
      <asp:ContentPlaceHolder runat="server" ID="cphContent" />
   </form>
</body>
</html>

在我的内容页面上,我的网格显示 cphContent 区域内的数据 - 在我的 cphSearch 区域中,我有许多输入控件 - 一个 RadioButtonList 和两个 DropDowns。目前,只要这些控件中的某些内容发生更改,就会发出回发(它们设置了AutoPostback="true")。

我的问题是:我如何告诉我的UpdatePanel(我试图在cphContent 区域中环绕我的网格)“监听”来自cphSearch 的这三个控件的回发?

<asp:UpdatePanel>
   <ContentTemplate>
      <asp:GridView>
         // grid view defined here
      </asp:GridView>
   </ContentTemplate>
   <Triggers>
      <asp:AsyncPostBackTrigger ControlID=".. what values to put here?? .." />
      <asp:PostBackTrigger ControlID=".. - what values to put here?? .." />
   </Triggers>

当我添加我的&lt;asp:UpdatePanel&gt; 时,我得到一个部分&lt;Triggers&gt;,但是cphSearch 内容区域中的那些控件不可见,所以我想我真的不能将它们添加为更新触发器,对吗?

要么我完全没有得到它(绝对有可能!),要么我错过了一个明显的步骤/技巧来让它工作 - 或者这是不可能的。告诉我!

【问题讨论】:

    标签: asp.net asp.net-ajax updatepanel partial-page-refresh


    【解决方案1】:

    我认为当您无法找到Triggers 的控制权时,我认为没有必要一直输入Triggers 某些事件只需使用没有triggers 的更新面板

    <asp:Content ID="Content1" ContentPlaceHolderID="cphSearch" runat="Server">
      <asp:UpdatePanel ID="updateSearch" runat="server">
        <ContentTemplate>
           your searching controls
        </ContentTemplate>
      </asp:UpdatePanel>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="Server">
      <asp:UpdatePanel ID="updateContent" runat="server">
        <ContentTemplate>
            your grid
        </ContentTemplate>
      </asp:UpdatePanel>
    </asp:Content>
    

    这将更新整个网格,搜索控件,它还将处理 AutoPostBack 事件,但不要忘记将 Update &lt;asp:UpdateProgress&gt; 控件放入以查看工作正在进行中...

    【讨论】:

    • 不知道为什么-但这似乎确实有效-谢谢!我一直认为您必须告诉 UpdatePanel 哪些事件会触发部分页面更新...
    【解决方案2】:

    根据这些信息,我假设您在 MasterPage 上拥有所有页面通用的搜索控件。一种方法是从您的母版页公开一个事件并在您的内容页上处理它。检查this

    在您的 DDL selectedIndexChanged 事件中引发此事件。在 contentPage 上此事件的处理程序中,您调用 updateContent.Update()。

    我认为解决方案就在这些方面。

    【讨论】:

    • 不完全是 - 这些搜索控件取决于显示的内容 - 它们位于 ContentPlaceHolder 内(在母版页中定义) - 但它们在母版上页面本身(也不是所有内容页面都相同)
    • 所以您的 GV 和搜索控件是您的意思是同一内容页面的一部分?我没有得到清晰的画面。您能否更新包含搜索控件的代码。
    • 否 - 搜索控件在一个文件中并放置在 cphSearch 容器中,而 gridview 在另一个文件中并放置在 cphContent 容器中
    • 另一个文件?你的意思是他们是独立的用户控件?
    • 是的,完全正确 - 两个独立的用户控件被放置在基于母版页的页面上的不同内容区域中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多