• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

retain viewstate on breadcrumb sitemap

hi there; using asp.net 2.0 (vb), i have a web.sitemap file that contains the architecture of my pages.

one of the pages lists results of a search and, when clicked, takes the user to the page requested.

in the "breadcrumbs" it displays Home > Results > Institution

if the user clicks the back button, they are brought back to the results page (listing all their results) ...  however, if the user selects results from the breadcrumb, the results are lost.

my question is, how would i retain this information so that when the breadcrumb is clicked, the (viwstate) results are retained?

thanks all.
0
vbnewbie01
Asked:
vbnewbie01
  • 2
  • 2
1 Solution
 
aki4uCommented:
0
 
vbnewbie01Author Commented:
hi, aki4u; thank you for the response and the link ... unfortunately, this didn't help as it is in C# and it's methods are unfamiliar to me (even in vb) .... i was hoping for a little more 'user friendly' explanation using vb ... but thanks again.
0
 
aki4uCommented:
In other words this can be done by saving the current ViewState into Session object and by Overriding: SavePageStateToPersistenceMedium, LoadPageStateFromPersistenceMedium and DeterminePostBackMode. You can find more info in VS help file. Here is the vb version of the code (vb files)

Default.aspx

    Protected Overrides Function DeterminePostBackMode() As System.Collections.Specialized.NameValueCollection
        If Not (Session("DateValue") Is Nothing) Then
            Return Request.Form
        Else
            Return MyBase.DeterminePostBackMode()
        End If
    End Function 'DeterminePostBackMode


    Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
        If Not (Session("DateValue") Is Nothing) Then
            Return Session("ViewState")
        Else
            Return MyBase.LoadPageStateFromPersistenceMedium()
        End If
    End Function 'LoadPageStateFromPersistenceMedium


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Me.IsPostBack Then
            DateValue.Text = DateTime.Now.ToString("d")
        End If
        If Not (Session("DateValue") Is Nothing) Then
            DateValue.Text = CType(Session("DateValue"), DateTime).ToString("d")
            Session("DateValue") = Nothing
        End If
    End Sub 'Page_Load


    Protected Sub NameValue_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub 'NameValue_TextChanged
    ' Necessary to Force Posted Value into Page ViewState

    Protected Sub OtherValue_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub 'OtherValue_TextChanged
    ' Necessary to Force Posted Value into Page ViewState

    Protected Sub DateSubmit_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("DateValue") = DateTime.Parse(DateValue.Text)
        Context.Items("RedirectPage") = "SelectDate.aspx"
    End Sub 'DateSubmit_ServerClick


    Protected Sub SubmitValues_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        SubmitResults.Text = "Name: " + NameValue.Text + "<br>Other: " + OtherValue.Text + "<br>Date: " + DateValue.Text
    End Sub 'SubmitValues_Click


    Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)
        If Not (Context.Items("RedirectPage") Is Nothing) Then
            Session("ViewState") = viewState
            Response.Redirect(Context.Items("RedirectPage").ToString())
        Else
            MyBase.SavePageStateToPersistenceMedium(viewState)
        End If
    End Sub 'SavePageStateToPersistenceMedium



SelectDate.aspx

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (Session("DateValue") Is Nothing) Then
            Calendar.SelectedDate = CType(Session("DateValue"), DateTime)
            Session("DateValue") = Nothing
        End If
    End Sub

    Protected Sub Calendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar.SelectionChanged
        Session("DateValue") = Calendar.SelectedDate '
        Response.Redirect("Default.aspx")
    End Sub
0
 
vbnewbie01Author Commented:
thanks, aki4u; i've discovered that i must use a session variable.  thanks for the response.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now