【问题标题】:Ajax Update Panel Causes Full Page LoadAjax 更新面板导致整个页面加载
【发布时间】:2012-09-11 18:07:47
【问题描述】:

我正在使用 VB.Net,问题是无论我如何尝试,我的更新面板都会导致整个页面加载。当我从网站下载示例代码并运行时,它可以工作!!!即使我将这些示例中的全部代码复制到我新创建的网络表单中并运行,它仍然会刷新整个页面!可能是什么问题呢? PS。我已经在我的 web.config 中尝试过,但并没有什么不同! :(

WebForm1.aspx

   <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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 id="Head1" runat="server">
    <title>How to use UpdatePanel</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

        <asp:Label ID="lblTime1" runat="server" /><br />
        <asp:Button ID="butTime1" runat="server" Text="Refresh Panel" /><br /><br />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="butTime1" EventName="Click" />
                <asp:PostBackTrigger ControlID="butTime2" />
            </Triggers>

            <ContentTemplate>
                <asp:Label ID="lblTime2" runat="server" /><br />
                <asp:Button ID="butTime2" runat="server" Text="Refresh Page" /><br />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />

        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
            </Triggers>

            <ContentTemplate>
                <asp:Label ID="lblTime3" runat="server" /><br />
            </ContentTemplate>
        </asp:UpdatePanel>

        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
            <asp:ListItem>Change</asp:ListItem>
            <asp:ListItem>My</asp:ListItem>
            <asp:ListItem>Value</asp:ListItem>
        </asp:DropDownList>
    </form>
</body>
</html>

WebForm1.aspx.vb

 Public Partial Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lblTime1.Text = DateTime.Now.ToString("T")
        lblTime2.Text = DateTime.Now.ToString("T")
        lblTime3.Text = DateTime.Now.ToString("T")
    End Sub
End Class

【问题讨论】:

  • 请提交您的代码
  • 检查ScriptManager的控件EnablePartialRendering属性值
  • 我确实添加了EnablePartialRendering,但它仍然刷新了整个页面:(这是我的ajax问题吗?为什么如果我运行下载的示例代码它可以正常工作,但当我复制并粘贴确切的代码时却不行然后跑?
  • 请发布您正在加载的脚本...您是否缺少任何 jQuery 参考资料?
  • 如果您来自搜索引擎:确保您没有Response.Redirect(...) 或来自代码隐藏的排序。因为这个原因,我刚刚损失了半个小时。

标签: asp.net ajax vb.net updatepanel


【解决方案1】:

如果您有一个从 .net framework v1.1 升级的旧项目,请从您的网络配置中删除此行以使其正常工作:

<xhtmlConformance mode="Legacy"/>

Google 了解删除上述内容的影响,但请记住,现在是 2018 年,这不再是一个真正的问题,而且我一定是唯一一个不幸的人仍然在 2003 年开始编写代码:(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多