C
Carlo Razzeto
I have a few user controls which use the view state to store the UI value.
I'm running into a bit of an odd error. Many of my controls use a hidden
value in the form to store the data. The reason for this is to seperate the
internal value from the display, and still allow users to access the control
data by using Request.Form("ControlName"). In order to populate the .Text
property, I have a UserControl.Init event handler which basically does the
following:
sub Page_Init( ... ) handles me.init
Text = Request.Form(ClientID)
end sub
The set for the text property stores this directly into the view state like
ViewState(ClientID + ":Text") = value.
In this control, I also have a PreRender event handler. This event handler
will populate the display items for the control, as well as set any
javascript etc.
Sub Page_PreRender( ... ) Handles me.prerender
txtDisplay.Text = GetDisplayText()
txtDisplay.Attributes.Add("onchange", "...")....
End Sub
What I've found by stepping through the code is the following...
When the Text property is set in the Page_Init method, the value is correct
as per the controls state when the form was posted. For some reason, when it
gets to the Page_PreRender method, all of the sudden instead of the
VeiwState containing the updated text value, it has the text value that was
set when the page was initally loaded. Why is this? It seems like
ViewState() = ... does not store values between various page events. This
seems like a rather peculier behaviour to me (which also seems to defeat the
purpose of ViewState as I understand it). Thanks for any thoughts
Carlo
I'm running into a bit of an odd error. Many of my controls use a hidden
value in the form to store the data. The reason for this is to seperate the
internal value from the display, and still allow users to access the control
data by using Request.Form("ControlName"). In order to populate the .Text
property, I have a UserControl.Init event handler which basically does the
following:
sub Page_Init( ... ) handles me.init
Text = Request.Form(ClientID)
end sub
The set for the text property stores this directly into the view state like
ViewState(ClientID + ":Text") = value.
In this control, I also have a PreRender event handler. This event handler
will populate the display items for the control, as well as set any
javascript etc.
Sub Page_PreRender( ... ) Handles me.prerender
txtDisplay.Text = GetDisplayText()
txtDisplay.Attributes.Add("onchange", "...")....
End Sub
What I've found by stepping through the code is the following...
When the Text property is set in the Page_Init method, the value is correct
as per the controls state when the form was posted. For some reason, when it
gets to the Page_PreRender method, all of the sudden instead of the
VeiwState containing the updated text value, it has the text value that was
set when the page was initally loaded. Why is this? It seems like
ViewState() = ... does not store values between various page events. This
seems like a rather peculier behaviour to me (which also seems to defeat the
purpose of ViewState as I understand it). Thanks for any thoughts
Carlo