ASP:按钮 OnClick 事件未在某一特定实例中触发

发布于 2024-11-16 19:08:04 字数 619 浏览 5 评论 0原文

我所拥有的是在用户控件中定义的弹出窗口,该弹出窗口在任务栏用户控件中打开,该控件附加到母版页,这样:

MasterPage.TaskBarUC.PopupUC

在弹出窗口中,有两个按钮,一个用于保存用户尝试的内容在数据库内执行,一取消。我有一些隐藏代码可以在用户单击任一按钮时完成工作。

因此每个页面都有任务栏,他们可以单击任务栏上的按钮来访问弹出窗口并保存信息。它工作完美。但是,站点内有一个特定页面需要通过页面上的按钮以及任务栏访问相同的弹出窗口。

该按钮可以工作,并且会打开弹出窗口,但由于某种原因,并且仅在这种情况下,“保存”按钮不会激活我的隐藏代码。它确实执行了我让它做的验证。同样奇怪的是,取消按钮也激活了一些隐藏代码,确实做了它应该做的事情。

我尝试在“保存”事件处理程序的开头放置一个断点,但它永远不会到达它。就好像该按钮只是进行验证,并完全忽略其 OnClick 事件。

.aspx

<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" 
    ValidationGroup="Validation" />

What I have is a popup defined within a user control, that is opened within a taskbar user control, which is attached to a master page, such that:

MasterPage.TaskBarUC.PopupUC

Within the popup, there are two buttons, one to save what the user is trying to do within a database, and one to cancel. I have some codebehind that does the work when the user clicks either button.

So every page has the taskbar, and they can click a button on the taskbar to access the popup and save the information. It works perfectly. However, there is one specific page within the site that needs to access the same popup from a button located on the page, as well as from the taskbar.

The button works, and it opens the popup, but for some reason, and only in this case, the "Save" button doesn't activate my codebehind. It DOES perform the validation that I have it do though. What is also weird is that the cancel button, which also activates some codebehind, does do what its supposed to.

I tried putting a breakpoint right at the beginning of my "Save" event handler, and it never reaches it. Its as if the button is only validating, and completely ignoring its OnClick event.

.aspx

<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" 
    ValidationGroup="Validation" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

咿呀咿呀哟 2024-11-23 19:08:04

我猜发生的情况是验证过程失败,这取消了 Button.Click 事件的处理。

要检查这种可能性,请尝试将 Button.CausesValidation 属性的值设置为 false 并查看 Button.Click 处理是否会继续或不。

I guess what happens is that the validation process has failed, which cancel the handling of the Button.Click event.

To check this possibility try to set the value of the Button.CausesValidation property to false and see if the Button.Click handling is going to continue or not.

忘你却要生生世世 2024-11-23 19:08:04

Button.CausesValidation 属性设置为 false 对我有用。我正在为不同的按钮使用必填字段验证器。我认为即使对于所有其他按钮单击事件(服务器端),这也可能会停止回发。

Button.CausesValidation property to false worked for me. I am using required field validator for different button. I think this could stop post back even for all other button click events (serverside).

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