Checkmark not saving state on round trip

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

Even though I have EnableViewState set to true, CheckBox1 is not retaining
its value (false) on page reload.

I have an OnLoad page sub that queries a SQL table for the member's record.

I use Dim bolLoadedOnce As Boolean in the codebehind class for the page.

Then I use:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

If bolLoadedOnce = True Then

Else
fLoadMemberSettings()
bolLoadedOnce = True
End If

End Sub

When I un-tick CheckBox1 it automatically fires a page reload which loads up
CheckBox1 as True again. I want it to remember that I un-ticked it.
 
Thanks.

That did it.

Eliyahu Goldin said:
Get rid of bolLoadedOnce. It 1) doesn't survive postbacks and 2) already
provided by ASP.NET as IsPostBack property.

Use IsPostBack.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Mark B said:
Even though I have EnableViewState set to true, CheckBox1 is not
retaining its value (false) on page reload.

I have an OnLoad page sub that queries a SQL table for the member's
record.

I use Dim bolLoadedOnce As Boolean in the codebehind class for the page.

Then I use:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If bolLoadedOnce = True Then

Else
fLoadMemberSettings()
bolLoadedOnce = True
End If

End Sub

When I un-tick CheckBox1 it automatically fires a page reload which loads
up CheckBox1 as True again. I want it to remember that I un-ticked it.
 
Hi Mark,

From your description and the code snippet you provided, you use a page
variable to hold the status of an operation, and you found that the value
is not persisted between page postback, correct?

In the code, I only see you access and set the "bolLoadedOnce" property,
but haven't seen you store this property into any storeage such as
ViewState or SessonState. By default, such an page variable will not be
persisted into page's ViewState automatically. If you need to maintain it
between postback, you'll need to store it manually, or directly access
page's ViewState to store/retrieve the value. e.g.

====================

If Page.ViewState("xxx") is Nothing Then
'do work
Page.ViewState("xxx") = "some value"

Else


End If
.......
================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
Back
Top