ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Async. Postbacks cause Page_Init? (C#)

2022-08-30 17:30:20  阅读:201  来源: 互联网

标签:load called C# init page Init Postbacks Page


Async. Postbacks cause Page_Init? (C#)

问题

I'm experiencing a very strange problem...

I have a regular ASP.Net webpage with a page_init and a page_load function. It is my understanding(from everywhere I look) that page_init gets called on the first page load(as in, not ever called in a postback) and page_load is called anytime something happens with the page.(It is very hard finding any info about this except for dead links and stuff about the page life cycle)

Well, I have an update panel containing other update panels and other assorted controls. Anytime I edit one of these controls, an async postback happens but instead of only page_load being called, page_init is also called which isn't suppose to happen(and didn't happen before a big codebase change)

So I would like to know anything that might cause this behavior or just if my idea of how page events are called is wrong.

 

回答1

I think you have the wrong idea of the page load life cycle. The OnInit event is called on EVERY request. Having the Page_Init method in your code behind is a shorthand way of wiring up the pages OnInit event.

Now I believe that you are confusing this with the "IsPostBack" property which will be set to true if a page posts back to itself i.e. when you click a Button etc. My guess is what you need to do is add an if statement in your Page_Init method i.e.

if(!IsPostBack){
//Do something to to update the UI
}

 

 回答2

Page_Init is definitely called on every page hit, postback or not, exactly the same as Page_Load.

The misconception that Page_Init doesn't get called on every request seems to be a common one.

Are you certain that this wasn't happening before your "big codebase change"?

 

回答3

Your Page_Init as well as Page_Load both methods should be called each time.

 

 

 

标签:load,called,C#,init,page,Init,Postbacks,Page
来源: https://www.cnblogs.com/chucklu/p/16640163.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有