handle event before Page_Load

走远了吗. 提交于 2020-01-03 08:27:12

问题


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


回答1:


I would use Page_PreLoad instead of Page_Init, because it is raised after all postback data is processed.




回答2:


Try Page_Init




回答3:


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.



来源:https://stackoverflow.com/questions/373885/handle-event-before-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!