在Page_Load之前处理事件
我有一个 ASP.NET 网页,其中包含大量在页面的 Page-Load 事件中处理的代码。 我在页面上还有一个下拉框,应该使用新值重新加载页面,但我想在处理整个页面加载代码之前获取这个新值。 我正在尝试了解 ASP.NET 页面生命周期。
我应该将页面加载代码移至稍后的事件,还是有办法在页面加载事件开始之前获取下拉列表值的值?
TIA
I have an asp.net web page with a ton of code that is handled in the Page-Load event of the page. I also have a dropdown box on the page that should reload the page with a new value, but I would like to get this new value before I process the entire Page-Load code.
I am trying to get my head around ASP.NET page lifecycle.
Should I move the Page-Load code to a later event or is there a way to get the value of the dropdown list value before the the Page-Load event begins?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 Page_PreLoad 而不是 Page_Init,因为它是在处理所有回发数据后引发的。
I would use Page_PreLoad instead of Page_Init, because it is raised after all postback data is processed.
尝试Page_Init
Try Page_Init
如前所述,Page_Init 就是您想要的。 但我恳请您使页面尽可能松散耦合。 首先看看 MVP 模式。 另外,请确保大部分逻辑都在域对象中。
Page_Load 事件中不应该有太多代码。 如果有,应该将其分解为简洁的方法,这样就不会出现疯狂的代码。
As noted before, Page_Init is what you want. But I emplore you to make your pages as loosly coupled as posible. Look into the MVP pattern for starters. Also, make sure that most of your logic is in your domain objects.
There shouldn't be too much code in the Page_Load event. If there is, it shoud be broken up into concise methods so that you don't have crazy code.