Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datalist state lost on postback

Datalist state lost on postback

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    werD
    wrote on last edited by
    #1

    hello everyone, sorry so long ive got an entry form that users are allowed to post to a log with. the form contains a datalist of checkboxes that are flags to filter by. when a user clicks certain checkboxes a radiobuttonlist showing parameters is displayed within the item. the problem occuring on postback is that the checkboxes and radios go back to there original state and i would lose files added to the listbox from the previous post back. In order to get around this i create a session value of a small structure that i use as a basic entry template. the structure contains 2 string collections that are related to files and flags. this method seems to work exactly as expected for the listbox control but i dont seem to be getting any of the values from my datalist added to the session value ie the flag collection retruns a count of zero. here is where im adding the values from files and from flags the for loop is the problem i suppose as the values for the file collection appear but none from the datalist 'skipping the bulk Dim str As String = "" str = smf.location0 & "," str &= smf.name1 & "," str &= smf.caption2 & "," str &= smf.type3 & "," str &= smf.id4.ToString smsg.StrFileCol.Add(str) Me.lblFileStatus.Text = "File added as " & smf.name1 For Each itm As DataListItem In Me.dlFlags.Items Dim chkbx As CheckBox = CType(itm.FindControl("chkFlag"), CheckBox) Dim hdn As HiddenField = CType(itm.FindControl("hdnFlagId"), HiddenField) Dim rdos As RadioButtonList = CType(itm.FindControl("rdoparam"), RadioButtonList) Dim flgstr As String = "" If chkbx.Checked = True Then If Not (rdos.SelectedValue =-1) Then flgstr = hdn.Value & "," flgstr &= rdos.SelectedValue Else flgstr = hdn.Value & "," flgstr &= 0 End If smsg.StrFlagCol.Add(flgstr) End If Next Session("smsg") = smsg 'also trying Session.Item("smsg") = smsg but they seem equivalent End If

    C 1 Reply Last reply
    0
    • W werD

      hello everyone, sorry so long ive got an entry form that users are allowed to post to a log with. the form contains a datalist of checkboxes that are flags to filter by. when a user clicks certain checkboxes a radiobuttonlist showing parameters is displayed within the item. the problem occuring on postback is that the checkboxes and radios go back to there original state and i would lose files added to the listbox from the previous post back. In order to get around this i create a session value of a small structure that i use as a basic entry template. the structure contains 2 string collections that are related to files and flags. this method seems to work exactly as expected for the listbox control but i dont seem to be getting any of the values from my datalist added to the session value ie the flag collection retruns a count of zero. here is where im adding the values from files and from flags the for loop is the problem i suppose as the values for the file collection appear but none from the datalist 'skipping the bulk Dim str As String = "" str = smf.location0 & "," str &= smf.name1 & "," str &= smf.caption2 & "," str &= smf.type3 & "," str &= smf.id4.ToString smsg.StrFileCol.Add(str) Me.lblFileStatus.Text = "File added as " & smf.name1 For Each itm As DataListItem In Me.dlFlags.Items Dim chkbx As CheckBox = CType(itm.FindControl("chkFlag"), CheckBox) Dim hdn As HiddenField = CType(itm.FindControl("hdnFlagId"), HiddenField) Dim rdos As RadioButtonList = CType(itm.FindControl("rdoparam"), RadioButtonList) Dim flgstr As String = "" If chkbx.Checked = True Then If Not (rdos.SelectedValue =-1) Then flgstr = hdn.Value & "," flgstr &= rdos.SelectedValue Else flgstr = hdn.Value & "," flgstr &= 0 End If smsg.StrFlagCol.Add(flgstr) End If Next Session("smsg") = smsg 'also trying Session.Item("smsg") = smsg but they seem equivalent End If

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Odds are you bind to your data source in page load on postback ( sorry, this was too long for me to read it all ). this rests the control state and your viewstate is lost.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      W 1 Reply Last reply
      0
      • C Christian Graus

        Odds are you bind to your data source in page load on postback ( sorry, this was too long for me to read it all ). this rests the control state and your viewstate is lost.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        W Offline
        W Offline
        werD
        wrote on last edited by
        #3

        Thanks for you response i got to trying this and it when i dont call databind on the datalist when its a postback it disappears. why is this? ive been binding and then trying to set these values checked or not with a session variable, but if this would work without that overhead i would be thrilled werD, MCP

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups