0

我正在使用 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
4

1 回答 1

-1

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

<xhtmlConformance mode="Legacy"/>

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

于 2018-10-29T16:24:51.740 回答