.NET:点击后退按钮会弄乱我的事件处理程序

发布于 2024-07-14 02:55:44 字数 470 浏览 4 评论 0原文

大家好。 我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱冒险 2024-07-21 02:55:44

您在搜索时是否按下了“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.

对你再特殊 2024-07-21 02:55:44

嗯...这听起来太奇怪了,不可能是真的。

我会检查事件处理程序是如何连接的(代码前面或代码后面),如果在代码后面,你确定它们绑定正确吗?

您是否尝试过清除浏览器缓存? 后退按钮可能会让您返回到旧版本的页面吗?

只是一个想法..您可以使用普通的旧 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)

挽清梦 2024-07-21 02:55:44

我通常看到的是浏览器回击后强制你刷新页面。 因此,要实际执行任何操作,您需要重新发布页面,从而重新发送点击。
您可以使用普通的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文