简体   繁体   English

Asp.net是否可以检查page_load是否触发了点击事件?

[英]Asp.net is it possible to check page_load a click event is triggered?

When a button is clicked, I would like to check whether a button is clicked in my page_load. 单击按钮后,我想检查是否在page_load中单击了按钮。 Is this possible? 这可能吗? I am using asp.net 2.0 C# 我正在使用asp.net 2.0 C#

You can check the IsPostBack flag to see if it was a postback rather than an initial load. 您可以检查IsPostBack标志以查看它是否是回发而不是初始加载。 This may be what you're after. 这可能就是您想要的。 Also, you can check the Request.Form["__EVENTTARGET"] from which you can obtain information about the control that raised the event and therefore find out if it was one of your buttons from there. 另外,您可以检查Request.Form["__EVENTTARGET"] ,从中您可以获取有关引发事件的控件的信息,从而可以确定该控件是否是其中的按钮之一。

The button click event will fire after the page load event has. 页面加载事件发生后,将触发按钮单击事件。 That being said, you can always check the http header to see what value is being pushed back through the request.form event. 话虽如此,您始终可以检查http标头,以查看通过request.form事件回推了什么值。 The button id will be in there if it has been fired. 如果按钮ID被触发,它将位于其中。

我可以通过以下方法来解决:创建一个隐藏字段并在单击某个按钮时更改值,然后在Page_Load中检查其值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM