PanelBar - Persist State in Cookie

Current page:

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

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 PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<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>

Find Assistance

Help Us Improve

Was this example helpful?