viewstate = false doesn't work

Discussion in 'ASP .Net' started by Dica, Jun 21, 2007.

  1. Dica

    Dica Guest

    i've got a simple page with a dropdown list of employees and a series of
    checkboxs showing their skills. the checkboxs are created dynamically from a
    sql statement and viewstate = false is set on each one. once the dropdown
    changes from one employee to another, the checkboxes are all recreated and i
    check the database to see if that particular employee has that skill. if so,
    i set the checkbox's checked state to true. however, when i look at the
    newly rendered page, the only checkboxs that are checked are those that i've
    manully checked. i could set the viewstate in the page directive, but that
    applies to all controls and i want the page to remember which employee was
    last selected.

    so, it looks like my script is initializing the checkboxes to the correct
    value initially, but after that .net steps in and sets them back to what was
    last posted even though i've set viewstate to all checkbox controls to
    false.

    anybody got any ideas what i'd doing wrong here?

    tks
     
    Dica, Jun 21, 2007
    #1
    1. Advertising

  2. Dica

    Patrice Guest

    Field values are not stored in the viewstate. By design a web page post
    field values to the server. The viewstate was created to store other values.
    So IMO your controls are just reinitialized from postback values.

    Double check your code. You likely forgot to initialize the values from the
    db after a postback ( it's likely that usually you don't bind again on a
    postback because the data are what you want to show but in this particular
    case the postback change the current set of data you wan't to display so you
    should bind again to your data).

    --
    Patrice


    "Dica" <> a écrit dans le message de news:
    %Wxei.6081$xk5.4250@edtnps82...
    > i've got a simple page with a dropdown list of employees and a series of
    > checkboxs showing their skills. the checkboxs are created dynamically from
    > a sql statement and viewstate = false is set on each one. once the
    > dropdown changes from one employee to another, the checkboxes are all
    > recreated and i check the database to see if that particular employee has
    > that skill. if so, i set the checkbox's checked state to true. however,
    > when i look at the newly rendered page, the only checkboxs that are
    > checked are those that i've manully checked. i could set the viewstate in
    > the page directive, but that applies to all controls and i want the page
    > to remember which employee was last selected.
    >
    > so, it looks like my script is initializing the checkboxes to the correct
    > value initially, but after that .net steps in and sets them back to what
    > was last posted even though i've set viewstate to all checkbox controls to
    > false.
    >
    > anybody got any ideas what i'd doing wrong here?
    >
    > tks
    >
     
    Patrice, Jun 21, 2007
    #2
    1. Advertising

  3. Dica

    Dica Guest

    "Patrice" <http://www.chez.com/scribe/> wrote in message
    news:%...
    > Field values are not stored in the viewstate. By design a web page post
    > field values to the server. The viewstate was created to store other
    > values. So IMO your controls are just reinitialized from postback values.


    yes. that's exactly what i'm seeing. what i'm trying to do is stop the asp
    net engine from repopulating these fields based on the posted back data and
    instead use the values i'm assigning as the dynamically created controls are
    initialized. i modified my page so that when the user drop down list is
    changed (causing a postback event) i capture the selected user to session
    and then response.redirect back to the same page. then, within page_load i
    get the selected user and call my routine to recreate the dynamic controls
    with the appropriate values. this works fine. so, it's something in the
    postback event i need to control, but how? if the solution is to rebind my
    data, in which event handler should it go? in other words, which event would
    fire after .net is done repopulating the form fields?

    tks

    >
    > Double check your code. You likely forgot to initialize the values from
    > the db after a postback ( it's likely that usually you don't bind again on
    > a postback because the data are what you want to show but in this
    > particular case the postback change the current set of data you wan't to
    > display so you should bind again to your data).


    >
    > --
    > Patrice
    >
    >
    > "Dica" <> a écrit dans le message de news:
    > %Wxei.6081$xk5.4250@edtnps82...
    >> i've got a simple page with a dropdown list of employees and a series of
    >> checkboxs showing their skills. the checkboxs are created dynamically
    >> from a sql statement and viewstate = false is set on each one. once the
    >> dropdown changes from one employee to another, the checkboxes are all
    >> recreated and i check the database to see if that particular employee has
    >> that skill. if so, i set the checkbox's checked state to true. however,
    >> when i look at the newly rendered page, the only checkboxs that are
    >> checked are those that i've manully checked. i could set the viewstate in
    >> the page directive, but that applies to all controls and i want the page
    >> to remember which employee was last selected.
    >>
    >> so, it looks like my script is initializing the checkboxes to the correct
    >> value initially, but after that .net steps in and sets them back to what
    >> was last posted even though i've set viewstate to all checkbox controls
    >> to false.
    >>
    >> anybody got any ideas what i'd doing wrong here?
    >>
    >> tks
    >>

    >
    >
     
    Dica, Jun 22, 2007
    #3
    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. matt del vecchio

    EnableViewState="False" doesn't work?

    matt del vecchio, Jan 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,179
    Craig Deelsnyder
    Jan 7, 2004
  2. Amar
    Replies:
    0
    Views:
    562
  3. Wayne Erfling
    Replies:
    0
    Views:
    469
    Wayne Erfling
    Oct 13, 2006
  4. Amar
    Replies:
    0
    Views:
    230
  5. Trapulo

    viewstate=false doesn't work

    Trapulo, Mar 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    227
    Scott M.
    Mar 6, 2005
Loading...

Share This Page