页面 OnLoad 未触发更改查询字符串
我遇到一个问题,当我导航到页面并仅更改查询字符串时,OnLoad 事件没有触发。如果我执行回发,则会调用它,然后更改查询字符串,然后调用更多 OnLoad。
这是我尝试的方法。我导航到 OnLoad fires -> 页面然后更改查询字符串页面更新(所有绑定元素都得到更新)OnLoad 不会触发 ->我使用按钮 OnLoad 进行回发 ->然后更改 OnLoad 触发的查询字符串。
我会尝试更详细地解释。
当我登录时,系统有登录窗口,我导航到另一个 aspx 页面,发送两个查询字符串消息,最后一个查询字符串是一个数字 (page.aspx?key=text82&key2=2010)。当我第一次访问页面时,PageLoad 事件被调用并且一切都很好,如果我在浏览器中将 key2 更改为 2011 并按 Enter 键,则 PageLoad 不会被调用,但所有绑定元素都会更新(GrivView 等..) 。如果我然后使用按钮进行回发,则会调用 PageLoad。如果我现在将 2011 更改回 2010 并按 Enter 键,则会调用 PageLoad。
我尝试这是 Firefox 每次都会调用 PageLoad 。
我厌倦了编写一个测试网站,但我没有遇到同样的问题,但我发现在 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&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();
}
I have a problem that the OnLoad event is not fireing when I navigate to a page and just change the query string. If I do a postback it is called, then changing the query string ones more OnLoad gets called.
Here is how i try. I navigate to the page OnLoad fires -> then change the query string page updates (all bound elements get updated) OnLoad does not fire -> I do a postback using a button OnLoad fires -> then change the query string OnLoad fires.
I will try to explain in more detail.
The system has log in window when I log in I navigate to an other aspx page sending two query string messages the last query string is a number (page.aspx?key=text82&key2=2010). When I get to the page the first time PageLoad event gets called and all is fine, if I in the browser change the key2 to 2011 and press enter the PageLoad does not get called but all my bound elements get updated (GrivView etc..). If I then do a postback using a button the PageLoad gets called. If I now change the 2011 back to 2010 and press Enter PageLoad is called.
I try this is firefox the PageLoad get called every time.
I tired to write a test website but I do not get the same problem, but what i found out is that in IE 8 changing the query string to the same number and pressing enter the PageLoad is not called. But doing so in firefox makes the postback fire. Here is the test code
<%@ 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&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>
Navigates to
<%@ 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 event Default2.aspx
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text += "Called " + DateTime.Now.ToString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题所在。看起来浏览器缓存给了我这个问题。按F12清除缓存,就可以了。
I found out the problem. Looks like the browser cache was giving me the problem. Press F12 and cleared the cache, it works.