【问题标题】:Page OnLoad not fireing changing query stringPage OnLoad 未触发更改的查询字符串
【发布时间】:2010-12-02 19:30:09
【问题描述】:

当我导航到一个页面并只是更改查询字符串时,我遇到了一个问题,即 OnLoad 事件没有触发。如果我进行回发,则会调用它,然后更改查询字符串更多的 OnLoad 会被调用。

这是我尝试的方法。我导航到页面 OnLoad 触发 -> 然后更改查询字符串页面更新(所有绑定元素都得到更新) OnLoad 不触发 -> 我使用按钮 OnLoad 触发回发 -> 然后更改查询字符串 OnLoad 触发。

我会尽量详细解释。

当我登录时系统有登录窗口我导航到另一个 aspx 页面发送两条查询字符串消息最后一个查询字符串是一个数字 (page.aspx?key=text82&key2=2010)。当我第一次调用 PageLoad 事件并且一切正常时,如果我在浏览器中将 key2 更改为 2011 并按 Enter,则不会调用 PageLoad,但我的所有绑定元素都会更新(GrivView 等) .如果我然后使用按钮进行回发,则调用 PageLoad。如果我现在将 2011 改回 2010 并按 Enter,则调用 PageLoad。

我尝试这是每次调用 PageLoad 的 firefox。

我厌倦了写一个测试网站,但我没有遇到同样的问题,但我发现在 IE 8 中将查询字符串更改为相同的数字并按 Enter 不会调用 PageLoad。但是在 Firefox 中这样做会使回发火。这是测试代码

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"     AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Welcome to ASP.NET!
</h2>
<p>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx?t=tt&   tttttt=2010">HyperLink</asp:HyperLink>
</p>
<p>
    You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
        title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>

导航到

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Button ID="Button1"
    runat="server" Text="Button" />
</asp:Content>

OnLoad 事件 Default2.aspx

protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text += "Called " + DateTime.Now.ToString();
}

【问题讨论】:

  • 您的问题不清楚,您能否再解释一下并发布您的 OnLoad() 代码。
  • Jeevan 说了什么;还要发布为什么您认为没有调用 Load 事件。确保包括整个方法,包括签名。还可能包括您设置事件处理程序的代码,如果您这样做的话,并让我们知道该代码的位置。
  • 我将尝试在此编写一些代码,因为每次使用 firefox 时都会调用 OnLoad。

标签: asp.net .net-4.0 page-lifecycle


【解决方案1】:

我发现了问题。看起来浏览器缓存给了我这个问题。按 F12 并清除缓存,它可以工作。

【讨论】:

    猜你喜欢
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多