.NET ASPX page life cycle
-
I am very confused by .NET ASPX page processing model. I am using C# and creating simple database data dependant dynamic form with bunch of generated buttons. After that I am catching server side processed standard onclick events on these buttons and in onclick event function creating some other dynamic elements such as textboxes and other buttons. When I am pressing on new one created buttons generated outside page_load function - page reloads and these elements (of course) is lost! Now I am using some sick mytype in Session wich holds my dynamic cotrols and restores them by page_load. I suppose this is not the recommended way to do things (but for now) it works very well, maybe there is some logic and normal way to hold dynamically created elements in page. And I am wandering why .NET guys destroys page instance on each event?
-
I am very confused by .NET ASPX page processing model. I am using C# and creating simple database data dependant dynamic form with bunch of generated buttons. After that I am catching server side processed standard onclick events on these buttons and in onclick event function creating some other dynamic elements such as textboxes and other buttons. When I am pressing on new one created buttons generated outside page_load function - page reloads and these elements (of course) is lost! Now I am using some sick mytype in Session wich holds my dynamic cotrols and restores them by page_load. I suppose this is not the recommended way to do things (but for now) it works very well, maybe there is some logic and normal way to hold dynamically created elements in page. And I am wandering why .NET guys destroys page instance on each event?
The Page object has a bool IsPostBack property. Put your form loading code inside an "if" statement only if IsPostBack is false.