Last post May 09, 2016 07:48 PM by march11
Apr 26, 2013 03:37 PM|dobbinjp|LINK
I have a gridview that for each row contains three sliders. I would like to know how to retain the selected slider value when a user clicks their back button. I am using master pages, VB.NET and building the sliders dynamically...right now all selections
are gone when a user clicks the browser back button. My code is as follows:
'page load function
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If IsPostBack Then
'I am omitting some code here for ease of reading...what follows is the table adapter code
Dim scenarioAdapter As New vw_scenariosTableAdapter()
Dim dtScenario As New DataTable()
dtScenario = scenarioAdapter.GetData()
'rename first column to an easier to read name
dtScenario.Columns("SCENARIO_DESC").ColumnName = "Scenario Description"
'add columns to hold slider controls for frequency and consequence selections
'set primary key to nothing so the column can be hidden
dtScenario.PrimaryKey = Nothing
GridView1.DataSource = dtScenario
Catch ex As Exception
'code to create the dynamic slider controls
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'this sets the ID of each slider control so I know what I am working with
Dim lastnumber As String = e.Row.Cells(0).Text
'frequency slider control
Dim freqSlider As New TextBox
freqSlider.ID = "freqSlider" & lastnumber
'frequency slider control bound label
Dim freqSliderBoundControl As New Label
freqSliderBoundControl.ID = "freqSliderBoundControl" & lastnumber
'add frequency slider behavior
Dim freqSliderExtender As New AjaxControlToolkit.SliderExtender
freqSliderExtender.BehaviorID = "freqSlider" & lastnumber
freqSliderExtender.TargetControlID = "freqSlider" & lastnumber
freqSliderExtender.BoundControlID = "freqSliderBoundControl" & lastnumber
freqSliderExtender.Orientation = AjaxControlToolkit.SliderOrientation.Horizontal
freqSliderExtender.Minimum = "1"
freqSliderExtender.Maximum = "6"
freqSliderExtender.Steps = 6
freqSliderExtender.EnableHandleAnimation = True
This might be a really easy question, but I am very confused to the postback versus view state and how to make sense of what is happening in terms of the page life cycle when a user clicks a back button.
Thanks in advance for any assistance!
May 09, 2016 07:48 PM|march11|LINK
Well, the back button is a bite to deal with some times especially when you are custom coding controls.
Here is a thought. Create a Session("variable") for each of the 3 categories you described. Make certain that these sessions are updated when the user makes changes to the page.
Then if the user comes back to the pages, load the slider settings based on the session values. You may also need to save a setting that indicates that the session values have been set.
Also, you will need to look into session time out values so that you can check of the page has truly been abandon, like If the use comes back days later. The default session I think is 20 mins, I don't recall, but you may need something different.