Checkmark not saving state on round trip

Discussion in 'ASP .Net' started by Mark B, Jun 24, 2008.

  1. Mark B

    Mark B Guest

    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.
    Mark B, Jun 24, 2008
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:uln%...
    > 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.
    Eliyahu Goldin, Jun 24, 2008
    #2
    1. Advertising

  3. Mark B

    Mark B Guest

    Thanks.

    That did it.

    "Eliyahu Goldin" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:uln%...
    >> 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.

    >
    >
    Mark B, Jun 24, 2008
    #3
  4. 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:
    .

    ==================================================
    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.



    --------------------
    >From: "Mark B" <>
    >Subject: Checkmark not saving state on round trip
    >Date: Tue, 24 Jun 2008 18:05:31 +1200


    >
    >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.
    >
    >
    Steven Cheng [MSFT], Jun 24, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Row
    Replies:
    1
    Views:
    683
    vMike
    Nov 26, 2003
  2. =?Utf-8?B?WWFuaXI=?=

    Sort table without round trip

    =?Utf-8?B?WWFuaXI=?=, Apr 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    727
    Steve Drake
    Apr 6, 2004
  3. Rathtap
    Replies:
    2
    Views:
    498
    Janaka
    Aug 24, 2004
  4. Replies:
    8
    Views:
    435
    =?Utf-8?B?TWF0SGVydGVs?=
    Oct 8, 2005
  5. =?Utf-8?B?TGFycnk=?=

    Disable web page controls during postback round-trip

    =?Utf-8?B?TGFycnk=?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    6,183
    Adrian Parker
    Mar 9, 2006
Loading...

Share This Page