.NET:点击后退按钮会弄乱我的事件处理程序
大家好。 我有一个 ASP.NET 页面,其中列出了一堆用户帐户。
如果我单击某个用户,则会触发名为 LinkChosen 的事件,该事件将打开该用户的帐户视图页面。
我还可以搜索用户,从而缩小列表范围。 该事件称为 btnSearch_click
如果我单击某个用户,则会调用 LinkChosen(),然后我会进入一个新页面。 如果我点击后退按钮,并尝试进行搜索,它仍然会触发 LinkChosen() 事件,而不是触发 btnSearch_click(),并将我带到我在推回之前查看的帐户。 在点击帐户之前进行搜索就像它应该的那样。
我使用的是 C# 和 ASP.NET,此错误出现在 IE 中,但不会出现在 Firefox 中。
有人有什么想法吗?
谢谢。
澄清编辑:“显示单个帐户”操作是一个超链接,而不是一个按钮。 :)
Hey all. I have a ASP.NET page that lists a bunch of user accounts.
If I click on a user, an event called LinkChosen is fired, which opens the account view page for that user.
I can also search for users, which narrows down the list. This event is called btnSearch_click
If I click on a user, LinkChosen() is called, and I'm taken to a new page. If I hit the back button, and try to do a search, instead of firing btnSearch_click(), it will still fire the LinkChosen() event and take me to the account I was viewing before pushing back.
Doing a search before clicking an account works like it should.
I'm using C# and ASP.NET, and this error appears in IE, but not Firefox.
Does anyone have any ideas?
Thanks.
Clarification edit: The "show single account" action is a hyperlink, not a button. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在搜索时是否按下了“Enter 键”? 如果是这样,页面中的第一个按钮通常是按 Enter 按键时提交的按钮。
您可以在页面或面板上设置 DefaultButton。
因此,如果您需要两个按钮都响应页面各自部分中的 Enter 键,请将它们包装在各自的 asp:Panel 中并设置 DefaultButton。
Are you pressing the "Enter Key" when you do a search. If so the first button in the page is usually the one that will get submitted on an Enter keypress.
You can set DefaultButton on the page, or on a panel.
So if you need two buttons to both respond to Enter presses in their respective portions of the page, wrape them both in their own asp:Panel with DefaultButton set.
嗯...这听起来太奇怪了,不可能是真的。
我会检查事件处理程序是如何连接的(代码前面或代码后面),如果在代码后面,你确定它们绑定正确吗?
您是否尝试过清除浏览器缓存? 后退按钮可能会让您返回到旧版本的页面吗?
只是一个想法..您可以使用普通的旧 asp:hyperlink 或 href="" 将您带到显示单个帐户的页面吗? IE 有 ShowAccount.aspx (或任何你叫它的东西)接受一个查询参数来告诉它要显示哪个帐户? (而不是使用回发/response.redirect)让您到达该页面? 我发现直接在 URL 上提供资源可以使开发变得更加容易。 (尽管这与您的特定错误无关)
hmm... this sounds too weird to be true..
I'd check how the event handlers were hooked up (code-front or code-behind) if in codebehind, are you sure they are bound correctly.
Have you tried clearing the browser cache? might be that the back button throws you back to an older version of the page?
just a thought.. could you use plain old asp:hyperlink or a href="" to take you to the page that shows a single account? IE have the ShowAccount.aspx (or whatever you called it) take a query param that tells it which account to show? (instead of using a postback/response.redirect) to get you to the page? I find that making resources available directly on URLs makes developing easier overall. (though this is unrelated to your particular bug)
我通常看到的是浏览器回击后强制你刷新页面。 因此,要实际执行任何操作,您需要重新发布页面,从而重新发送点击。
您可以使用普通的 asp:hyperlink,而不是 asp:linkbutton。 您将保存回发,并完全避免该问题。
What I usually see is that the browser forces you to refresh the page after hitting back. So to actually do anything you are re-posting the page, which re-sends the click.
Can you use a normal asp:hyperlink, instead of an asp:linkbutton. You will save the postback, and avoid the issue completely.