|
|
|
start date: Sat, 28 Jul 2007 03:45:59 -0700,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Joe Abou Jaoude
|
|
2
Riki
|
|
3
Joe Abou Jaoude
|
Viewstate and preserving data on postbacks
hi,
I just want simply to preserve some data in my usercontrol on postbacks.
so I added this property in my UserControl
Protected Property MyProperty() As String
Get
If Not ViewState("xxx") Is Nothing Then
Return ViewState("xxx")
Else
Return ""
End If
End Get
Set(ByVal value As String)
ViewState("xxx") = value
End Set
End Property
However I lost the viewstate value on postbacks. I checked that my
usercontrol has enabledviewstate=true.
What I m doing wrong ?
If I replace in the code ViewState by Session , the data is preserved,
however session won't work for me.(case of two pages using the
usercontrol in the same session)
Thank you
*** Sent via Developersdex http://www.developersdex.com ***
Date:Sat, 28 Jul 2007 03:45:59 -0700
Author:
|
Re: Viewstate and preserving data on postbacks
Joe Abou Jaoude wrote:
> hi,
>
> I just want simply to preserve some data in my usercontrol on
> postbacks.
>
> so I added this property in my UserControl
>
> Protected Property MyProperty() As String
> Get
> If Not ViewState("xxx") Is Nothing Then
> Return ViewState("xxx")
> Else
> Return ""
> End If
> End Get
> Set(ByVal value As String)
> ViewState("xxx") = value
> End Set
> End Property
>
> However I lost the viewstate value on postbacks. I checked that my
> usercontrol has enabledviewstate=true.
> What I m doing wrong ?
> If I replace in the code ViewState by Session , the data is preserved,
> however session won't work for me.(case of two pages using the
> usercontrol in the same session)
Your code seems correct.
First, make sure that any code that initializes your property before
postback
is not executed again after postback.
Then, is your user control by any chance created dynamically (with New)?
In that case, make sure it gets the same id before and after the postback.
If not, viewstate is not preserved.
--
Riki
Date:Sat, 28 Jul 2007 15:37:21 +0200
Author:
|
Re: Viewstate and preserving data on postbacks
Hi Ricki,
Actually the user control is created dynamically using the
Page.LoadControl method. However I tested it in the case when it's not
created dynamically (I put the usercontrol in the page designer with an
ID of course) and I got the same result.
There's nothing that initializes my property before
postback, and anyway the probelem is that the viewstate("xxx") returns
nothing.All the entry was not preserved and not only the value.
ViewState.Count returns 0.
Regards
*** Sent via Developersdex http://www.developersdex.com ***
Date:Sun, 29 Jul 2007 23:32:07 -0700
Author:
|
|
|