This is a migrated thread and some comments may be shown as answers.

Save on each page load?

6 Answers 85 Views
Persistence Framework
This is a migrated thread and some comments may be shown as answers.
John Reynolds
Top achievements
Rank 1
John Reynolds asked on 15 Mar 2013, 03:58 AM
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.

6 Answers, 1 is accepted

Sort by
0
John Reynolds
Top achievements
Rank 1
answered on 15 Mar 2013, 04:12 AM
Nevermind please - found it.
0
danparker276
Top achievements
Rank 2
answered on 25 Jul 2013, 06:24 PM
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();
        }
    }


0
Peter Filipov
Telerik team
answered on 26 Jul 2013, 07:12 AM
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.
0
Keith
Top achievements
Rank 1
answered on 28 Mar 2014, 04:25 PM
Mind posting the solution?
0
John Reynolds
Top achievements
Rank 1
answered on 28 Mar 2014, 05:20 PM
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
0
Peter Filipov
Telerik team
answered on 03 Apr 2014, 03:30 PM
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.

 
Tags
Persistence Framework
Asked by
John Reynolds
Top achievements
Rank 1
Answers by
John Reynolds
Top achievements
Rank 1
danparker276
Top achievements
Rank 2
Peter Filipov
Telerik team
Keith
Top achievements
Rank 1
Share this question
or