page-lifecycle

Asp.net “Global” variables

十年热恋 提交于 2019-11-29 15:48:35
I'm writing a page in ASP.NET and am having problems following the cycle of initialization on postbacks: I have (something akin to) the following: public partial class MyClass : System.Web.UI.Page { String myString = "default"; protected void Page_Init(object o, EventArgs e) { myString = Request["passedString"]; //note that I've tried to set the default here in Init on NULL... } protected void Page_Load(object o, EventArgs e) { if(!Postback) { //code that uses myString.... } else { //more code that uses myString.... } } } And what's happening is that my code picks up the "passedString" just

Do I need to unsubscribe from (manually subscribed to) events in asp.net?

China☆狼群 提交于 2019-11-29 14:42:46
Do the same best practis rules regarding subscribing/unsubscribing to events apply in asp.net? I know it might seem like a silly question, but when I think about it, I have never really seen any code where people first subscribe to an event on a page and then unsubscribe later on in the web request. Example 1: On a page, in the Page_Load method, I subscribe to a updating event on a ListView. Should I unsubscribe from that event later on, for example in the OnPreRenderComplete method? Example 2: In the passive view patter, a view (Page control/Usercontrol) will raise an event whenever it needs

Difference with creating and adding controls in PreInit Init

谁说我不能喝 提交于 2019-11-29 13:43:25
There's tons of info on the web about the ASP.NET life cycle, but i can't seem to figure out when to dynamically add controls to the page. In general there are two situations; an aspx page with a masterpage, and one without. The book i'm currently reading (70-515 self prep) says to add controls to a page without a master page in the preinit eventhandler. To dynamically add controls to a contentpage, i should place that logic in the init eventhandler. According to MSDN (http://msdn.microsoft.com/en-us/library/ms178472.aspx) I should create or recreate dynamic controls in the preinit

How to detect page refresh in .net

不问归期 提交于 2019-11-29 12:27:17
问题 I have a Button_click event. While refreshing the page the previous Postback event is triggering again. How do I identify the page refresh event to prevent the Postback action? I tried the below code to solve it. Actually, I am adding a visual webpart in a SharePoint page. Adding webpart is a post back event so !postback is always false each time I'm adding the webpart to page, and I'm getting an error at the else loop because the object reference is null . if (!IsPostBack){ ViewState[

ViewState Chunking in asp.net

醉酒当歌 提交于 2019-11-28 23:40:46
I keep on hearing this words "Viewstate Chunking". What is Viewstate Chunking? And how it is working for ASP.NET pages? kril When the ViewState in your page becomes very large it can be a problem since some firewalls and proxies will prevent access to pages containing huge ViewState sizes. For this purpose ASP.NET introduces the ViewState Chunking mechanism. So ASP.NET enables splitting of the ViewState's single hidden field into several using the MaxPageStateFieldLength property in the web.config section. When the MaxPageStateFieldLength property is set to a positive number, the view state

Is there an after Page_Load event in ASP.net

Deadly 提交于 2019-11-28 17:12:52
Is there an event that is triggered after all Page_Load events have completed? How can i have more than one Page_Load ? When you have user controls. Before my page can render, i need my page (and all embedded controls) to have initialized themselves by completing their Page_Load events. The problem, of course, is that if i put code in my page's Page_Load handler: MyPage.aspx --> Page_Load ---> DoSomethingWithUserControl() UserControl1.ascx --> Page_Load ---> initialize ourselves now that viewstate has been restored then i begin to access my UserControl1 control before it is ready. i need a way

In ASP.Net, during which page lifecycle event does viewstate get loaded?

允我心安 提交于 2019-11-28 16:20:07
问题 I know it happens sometime before Load, but during what event exactly? 回答1: It's loaded into memory between init and load. See this article for a full break down of the page lifecycle. 回答2: I once got into this question too and got my answer from TRULY understanding Viewstate article, which I highly recommend. After reading it I designed a graphic that helped me to understand better what was happening on between each stage and when and how ViewState was doing its job. I'd like to share this

asp.net: what's the page life cycle order of a control/page compared to a user contorl inside it?

筅森魡賤 提交于 2019-11-28 15:25:58
I have an aspx and inside it an ascx. From a short testing I see the PageLoad of the aspx is called before the PageLoad of the user-Control but the opposite is true for OnInit. Does someone know what is the order of the events (page compared to a user-control inside it) Thanks You should look at this ASP.NET Page Life Cycle Overview and this Page: PreInit Control: Init Page: Init Page: InitComplete Page: PreLoad Page: Load Control: Load Page: LoadComplete Page: PreRender Control: PreRender Page: PreRenderComplete Page: SaveStateComplete Page: RenderControl Page: Render Control: RenderControl

Asp.net “Global” variables

被刻印的时光 ゝ 提交于 2019-11-28 08:50:39
问题 I'm writing a page in ASP.NET and am having problems following the cycle of initialization on postbacks: I have (something akin to) the following: public partial class MyClass : System.Web.UI.Page { String myString = "default"; protected void Page_Init(object o, EventArgs e) { myString = Request["passedString"]; //note that I've tried to set the default here in Init on NULL... } protected void Page_Load(object o, EventArgs e) { if(!Postback) { //code that uses myString.... } else { //more

Difference with creating and adding controls in PreInit Init

冷暖自知 提交于 2019-11-28 07:16:03
问题 There's tons of info on the web about the ASP.NET life cycle, but i can't seem to figure out when to dynamically add controls to the page. In general there are two situations; an aspx page with a masterpage, and one without. The book i'm currently reading (70-515 self prep) says to add controls to a page without a master page in the preinit eventhandler. To dynamically add controls to a contentpage, i should place that logic in the init eventhandler. According to MSDN (http://msdn.microsoft