Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Viewstate and preserving data on postbacks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Abou Jaoude - 28 Jul 2007 11:45 GMT
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
Riki - 28 Jul 2007 14:37 GMT
> hi,
>
[quoted text clipped - 22 lines]
> 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.

Signature

Riki


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.