T
Tom Wisnowski
Hello all,
Here is a simple example of what I'm doing...
Create a ASPX page
Add a PlaceHolder(plch) and a Button(btn) to the page.
In the code behind on Page_load add the following...
TextBox txt = new TextBox();
if(!IsPostBack)
{
txt.Text = "Hello";
txt.BackColor = Color.Yellow;
}
plch.Controls.Add(txt);
Run the page...
you will see the page renders the textbox correctly. Now
press the button to caused a postback. When the page is re-
rendered, the background color is cleared (it is never
loaded from the viewstate).
To test the viewstate issue, I created a new Custom
Control, MyTextBox, that inherits from TextBox. I
overrided the LoadViewState and SaveViewState methods to
add trace output so i could see when they fire. Here is
what i found...
When the page first loads, the control's SaveViewState is
called twice (Once right after the page's prerender and
once again in the page's SaveViewState, not sure why?).
On the first postback, the control's LoadViewState is
never called.
On Subsequent postbacks, the control's LoadViewState is
called right after the control is added to the
placeholder's controls collection.
Why is the first postback not calling the control's
LoadViewState? I assume this is the problem with my
example, the background color is lost because the first
postback never restores the object state, which clears the
background color.
I've been banging my head on this one for a while now and
ANY comments would be appreciated!
Thanks,
Tom Wisnowski, MCAD
I was also wondering...
I thought MSDN subscribers were suposed to get responses
posted back within 72 hours, But most of my posts go un-
answered. Is there a problem with my email alias?
Here is a simple example of what I'm doing...
Create a ASPX page
Add a PlaceHolder(plch) and a Button(btn) to the page.
In the code behind on Page_load add the following...
TextBox txt = new TextBox();
if(!IsPostBack)
{
txt.Text = "Hello";
txt.BackColor = Color.Yellow;
}
plch.Controls.Add(txt);
Run the page...
you will see the page renders the textbox correctly. Now
press the button to caused a postback. When the page is re-
rendered, the background color is cleared (it is never
loaded from the viewstate).
To test the viewstate issue, I created a new Custom
Control, MyTextBox, that inherits from TextBox. I
overrided the LoadViewState and SaveViewState methods to
add trace output so i could see when they fire. Here is
what i found...
When the page first loads, the control's SaveViewState is
called twice (Once right after the page's prerender and
once again in the page's SaveViewState, not sure why?).
On the first postback, the control's LoadViewState is
never called.
On Subsequent postbacks, the control's LoadViewState is
called right after the control is added to the
placeholder's controls collection.
Why is the first postback not calling the control's
LoadViewState? I assume this is the problem with my
example, the background color is lost because the first
postback never restores the object state, which clears the
background color.
I've been banging my head on this one for a while now and
ANY comments would be appreciated!
Thanks,
Tom Wisnowski, MCAD
I was also wondering...
I thought MSDN subscribers were suposed to get responses
posted back within 72 hours, But most of my posts go un-
answered. Is there a problem with my email alias?