在asp.net中,page_load发生在单选按钮OnCheckedChanged事件之前
我的 asp.net 页面上有两个单选按钮,其中 AutoPostBack = True
当我单击其中任何一个时,它们都会设置一个标志 SaveData=False
但是,当我单击它们时,page_load 事件首先发生,因此 page_load
事件会保存数据,然后触发 radiobutton_OnCheckedChanged
事件。
如何在 page_load
事件之前触发 OnCheckedChanged
?
I have two radio button on my asp.net page, with AutoPostBack = True
When I click on either of those, they each set a flag SaveData=False
However, when I click on them, the page_load event occurs first, so the page_load
event saves the data, then the radiobutton_OnCheckedChanged
event is triggered.
How can I trigger the OnCheckedChanged
before the page_load
event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你不能。
您需要阅读页面生命周期。
You can't.
You need to read up on the page lifecycle.
您无法在
radiobutton_OnCheckedChanged
之前触发OnCheckedChanged
,因为这是正常的页面生命周期。您可以在 Page_Load 中检查
Page.IsPostBack
是否为 true,然后不保存(或保存)数据。You can't trigger the
OnCheckedChanged
beforeradiobutton_OnCheckedChanged
because that's the normal page life cycle.You can check in Page_Load if
Page.IsPostBack
is true or not, and then don't save (or save) the data.Troy - 你必须在客户端处理这个问题(javascript / jquery)。
您的 AutoPostBack = True 会导致表单执行调用页面加载的回发。
这一切都与页面生命周期和服务器端事件如何工作有关。
Troy - you will have to take care of this on the client side (javascript / jquery).
Your AutoPostBack = True causes the form to do a postback which calls page load.
Its all about how the page lifecycle and server side events work.
您不能始终需要加载页面才能触发事件。这与控件创建、视图状态管理、控件状态等有关。
您想要在
Page_Load
中执行的操作类似于:您不想要执行的任何操作单击单选按钮时发生,请将其放入
if {}
块内。IsPostBack
指示页面正在处理回发事件,这是当您单击某个单选按钮时发生的情况。You can't the page always needs to load before events can be fired. This has to do with control creation, view state management, control state, etc.
What you want to do in your
Page_Load
is something like:Anything that you do not want to happen when the radio buttons are clicked, put it inside the
if {}
block.IsPostBack
indicates that the page is processing a post-back event, which is what happens when you click one of your radio buttons.您
无法更改
事件处理程序执行的顺序/顺序
。不过,您可以将 page_load 内的代码移至另一个事件处理程序
。You
can't change
theorder/sequence
of event handler execution. However you may move the code inside the page_load to anotherevent handler
.