Hi Egbert,
You're an IIS guy, so it should be obvious to you that each Request for an
ASPX page happens in a vacuum, as HTTP is stateless. What this means with
regards to your issue is that, when you dynamically load a Control class
into your Page, regardless of whether the Page is posted back or not, you
are loading a brand-new instance of the Control to a brand-new instance of
the Page.
The LoadViewState event occurs quite early on in the Control Execution
LifeCycle, right after the Init event. So, the solution to your dilemma is
to load your User Controls in the Init event of the Page.
The following .Net SDK article details the Events that occur in the
LifeCycle of every System.Web.UI.Control (including the Page class):
http://msdn.microsoft.com/library/de...nLifecycle.asp
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Egbert Nierop (MVP for IIS)" <eg***********@nospam.invalid> wrote in
message news:#J**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a complex asp.net 1.1 program that dynamically needs to load
controls (LoadControl)
The textboxes etc inside these controls keep viewstate and values but not
within
Page_Load()
when that event is 'going on' the load control happens but the values are
not yet 'filled in' They are filled in only -when- the pageload event has
been executed completely.
QUESTION: How to fix this behaviour?
So
Private MyControl myControl;
void PageLoad(object sender, EventArgs e)
{
this.myControl = (myControl) LoadControl("myControl.ascx");
myPlaceHolder.Controls.Add(myControl);
if (IsPostBack)
string temp = this.myControl.someProperty; // maps to internal
TextBox!
ïf (temp.Length == 0)
lblError.Text = "empty!";
}
}