New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Persist State in Cookie

Current page:

Normally, the state of RadPanelBar would be lost when navigating between pages unless you programmatically persist it or use the PersistStateInCookie property. This example demonstrates the latter- just set the PersistStateInCookie property to true.

State restoring occurs before the PreRender event of RadPanelbar. You can access the SelectedItem by subscribing to the PreRender (DataBound if you use declarative datasources) event.

Please review the code sections for more details.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" AutoEventWireup="true" Inherits="PanelBar.Examples.Functionality.PersistStateInCookie.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</head>

<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />

    <div class="demo-container size-thin">
        <telerik:RadPanelBar RenderMode="Lightweight" runat="server" ID="RadPanelBar1" PersistStateInCookie="True" Width="100%"
            OnPreRender="RadPanelBar1_PreRender">
            <Items>
                <telerik:RadPanelItem Text="ASP.NET controls" Expanded="true">
                    <Items>
                        <telerik:RadPanelItem NavigateUrl="DefaultCS.aspx?page=menu" Text="RadMenu" />
                        <telerik:RadPanelItem NavigateUrl="DefaultCS.aspx?page=combobox" Text="RadComboBox" />
                        <telerik:RadPanelItem NavigateUrl="DefaultCS.aspx?page=panelbar" Text="RadPanelBar" />
                        <telerik:RadPanelItem NavigateUrl="DefaultCS.aspx?page=treeview" Text="RadTreeView" />
                    </Items>
                </telerik:RadPanelItem>
                <telerik:RadPanelItem Text="WinForms controls">
                    <Items>
                        <telerik:RadPanelItem Text="RadMenustrip" NavigateUrl="DefaultCS.aspx?page=menustrip" />
                        <telerik:RadPanelItem Text="RadTabStrip" NavigateUrl="DefaultCS.aspx?page=tabstrip" />
                        <telerik:RadPanelItem Text="RadToolStrip" NavigateUrl="DefaultCS.aspx?page=toolbarstrip" />
                    </Items>
                </telerik:RadPanelItem>
                <telerik:RadPanelItem Text="Other projects">
                    <Items>
                        <telerik:RadPanelItem Text="SiteFinity" NavigateUrl="DefaultCS.aspx?page=sitefinity" />
                        <telerik:RadPanelItem Text="Reporting" NavigateUrl="DefaultCS.aspx?page=reporting" />
                        <telerik:RadPanelItem Text="RadAjax" NavigateUrl="DefaultCS.aspx?page=ajax" />
                    </Items>
                </telerik:RadPanelItem>
            </Items>
        </telerik:RadPanelBar>
        <div class="qsf-result">
            <h2>Current page:</h2>
            <p>
                <asp:Literal runat="server" ID="Label1" /></p>
        </div>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance