Datalist state lost on postback
-
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
-
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
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 )
-
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 )
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