Save on each page load?

7 posts, 0 answers
  1. John Reynolds
    John Reynolds avatar
    32 posts
    Member since:
    Sep 2008

    Posted 14 Mar 2013 Link to this post

    We're using the grid settings (GridSettingsPersister) to save the grid state on each page Page_PreRenderComplete, so that when the user returns later to the page it's always how they left it last. Conversely the Page_Load sets the state the first time.

    I can't seem to find any combination of methods to do that here.
  2. John Reynolds
    John Reynolds avatar
    32 posts
    Member since:
    Sep 2008

    Posted 14 Mar 2013 Link to this post

    Nevermind please - found it.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 25 Jul 2013 Link to this post

    On my master page I do.  It seems to be working

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rpmMaster.LoadState();
     
            }
    }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                
                rpmMaster.SaveState();
            }
        }


  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 26 Jul 2013 Link to this post

    Hello Dan,

    You are correct, that is how it could be implemented. For other approaches you could review our demos and documentation.

    Regards,
    Peter Filipov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Keith
    Keith avatar
    19 posts
    Member since:
    Aug 2012

    Posted 28 Mar 2014 in reply to John Reynolds Link to this post

    Mind posting the solution?
  7. John Reynolds
    John Reynolds avatar
    32 posts
    Member since:
    Sep 2008

    Posted 28 Mar 2014 in reply to Keith Link to this post

    Note that a while back we tried to move to the Persistence Framework, but it wasn't very mature. I think it's really worth trying that first before pursuing what we've done.

    Here is the page_prerendercomplete, which basically initializes the GridSettingsPersister and then does some things with cookies we use to store the settings.

    Private Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
     
        Dim gsp As New GridSettingsPersister(Me.Projects)
        MainGridState = gsp.SaveSettings
     
        ' Set the cookie with the current state.
     
        Dim ChocolateChip As New HttpCookie("PersistentApplicationSettings")
     
        ChocolateChip.Expires = Today.AddYears(1)
     
        ChocolateChip("MainGridState") = MainGridState
        ChocolateChip("MainGridStyle") = MainGridStyle
        ChocolateChip("MainGridColumns") = MainGridColumns
     
        If IsNothing(Response.Cookies("PersistentApplicationSettings")) Then Response.Cookies.Add(ChocolateChip)
     
        Response.Cookies.Set(ChocolateChip)
     
    End Sub



    On the page_load we have an area inside the If not me.ispostback which does the following:

    If Not Me.IsPostBack Then
     
        Try
            MainGridState = Request.Cookies("PersistentApplicationSettings")("MainGridState")
            MainGridStyle = Request.Cookies("PersistentApplicationSettings")("MainGridStyle")
            MainGridColumns = Request.Cookies("PersistentApplicationSettings")("MainGridColumns")
        Catch ex As Exception
            ' There're lots and lots and lots of reasons why that might bomb, from the cookie not existing to us changing it at some time to....
            MainGridState = ""
            MainGridStyle = "Paged"
            MainGridColumns = "Standard"
        End Try
     
        Me.ProjectView.SelectedValue = MainGridColumns
     
        Me.GridStyle.SelectedValue = MainGridStyle
     
        Dim gsp As New GridSettingsPersister(Me.Projects)
        Try
            gsp.LoadSettings(MainGridState)
        Catch ex As Exception
            ' That'll bomb out if we've never saved the settings before, if the grid has radically changed, etc., etc., etc.
            ' Regardless, the best thing to do is start with a clean slate of whatever the grid's settings happen to be at the moment.
            MainGridState = gsp.SaveSettings
        End Try
     
        FormatGrid()
     
    End If
  8. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 03 Apr 2014 Link to this post

    Hello John,

    Could please elaborate a bit on your case. What are you trying to persist which is not supported of the control. Your feedback will help us to improve it.

    Regards,
    Peter Filipov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017