Can Someone Explain this (ref Page Life Cycle)
-
I have made a user control ( text.ascx) with a text box (txtUserControl) and a button (btnUserControl) .
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="test.ascx.cs" Inherits="WebApplication1.test" %>
Now i load this usercontrol dynamically on (default.aspx) into two panels:public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { test tst = Page.LoadControl(@"~\test.ascx") as test; pnlDefaultOne.Controls.Add(tst); } protected void btnDefault_Click(object sender, EventArgs e) { test tst = Page.LoadControl(@"~\test.ascx") as test; pnlDefaultTwo.Controls.Add(tst); } }
Now, the question is about the beahviour of textbox (txtUserControl), and its viewstate. When i click btnDefault.. it loads the userControl in panelTwo. now when i enter values in both the textboxes (each of a usercontrol), and click the btnDefault, the value in the first control (the one loaded at page_load) is persisted, while in the other one which was loaded in btnEvent is NOT. i have read decent enough abt page cycle and am aware abt rendering, viewstate, postBackData. BUt cant really figure out the reason behind this. Any comment on the same will be of help. Thanks in advance.