【问题标题】:disable postback refresh on master page在母版页上禁用回发刷新
【发布时间】:2013-02-04 14:41:54
【问题描述】:

我有一个带有三个图像按钮的母版页。在母版页下方的内容中,我有列表框,当我选择列表中的项目时,它会在内容中打开一个新列表。问题是,当我进行选择时,整个页面都会重新加载,并且带有图像的母版页会重新加载,并且大约需要 1 秒钟才能全部返回。正如您可能理解的那样,这不是很方便,而且它不是供个人使用的程序。是否可以使回发仅适用于下面的字段而保持母版页不变?

母版页:

<%@ Master Language="VB"  CodeFile="MyMasterPage.master.vb" Inherits="MyMasterPage" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="topContent" align="center">
        <table>
            <tr>
                <td style="width:400px;" align="right" axis="top">
                </td>
                <td>
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/PetrolinaLetters.png" />
                </td>
                <td style="width:400px; text-align:center;" valign="top">
                <asp:Label ID="userText" runat="server" BorderStyle="Double" Width="130px" Font-Bold="True"></asp:Label>
                </td>
            </tr>
        </table>
        <div>
            <table>
                <tr>
                    <td style="width:170px;">
                        <asp:ImageButton ID="ImageButton1" runat="server" Height="30px" ImageUrl="~/orderButton.png"
                            Width="160px" />
                    </td>
                    <td style="width: 170px;">
                        <asp:ImageButton ID="ImageButton2" runat="server" Height="30px" ImageUrl="~/orderHistory.png"
                            Width="160px" />
                    </td>
                    <td style="width:170px;">
                        <asp:ImageButton ID="ImageButton3" runat="server" Height="30px" ImageUrl="~/changePass.png"
                            Width="160px" />
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

【问题讨论】:

  • 什么是“母版页下方的字段”MasterPage 没有“上方”或“下方”。
  • 代码??如果您想更新页面的特定区域而不是整个页面,请尝试 AJAX
  • srr 忘记添加代码。更新了,母版代码已经上线了

标签: asp.net master-pages


【解决方案1】:

您需要进行部分回发(又名:AJAX),以便不触及页面元素的其余部分,并且仍然具有列表元素所需的行为。

A- 使用 jquery 捕获更改的值,转到您的网络服务器,然后返回数据(快速,推荐,但需要一些工作)

一些有用的例子:

  1. http://jquerybyexample.blogspot.com/2012/04/how-to-populate-aspnet-dropdownlist.html
  2. jQuery-AJAX to rebind dropdown list to results from stored procedure
  3. http://amin-sayed.blogspot.com/2008/10/in-this-example-ill-demonstrate-how-to.html

B- 在控件周围使用更新面板,无需页面的其余部分即可更新它们(从性能角度来看不是那么快,但非常容易实现)

  1. http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
  2. http://www.asp.net/ajax/documentation/live/tutorials/IntroductionUpdatePanel.aspx
  3. http://www.netrostar.com/How-to-Use-NET-Update-Panel

【讨论】:

  • 不客气,如果这对您有帮助,请考虑“标记为答案”
猜你喜欢
  • 2011-02-07
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多