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

How do i clear the cookie set by PersistStateInCookie for the panel bar?

8 Answers 277 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 09 Oct 2009, 04:12 PM
I have a panel bar which i use to navigate around my application once the user has logged in.  The problem i have is when the user logs out and then comes back into the application i want ot lose the fact that they clicked on the log out item which is still highlighted and any item that has children remain expanded if they were at the time of log out.  So basically just want to clear the cookie that is holding the fact that the items are selected etc...

If I turn the PersistStateinCookie  to false then this gives me the reaction i want at logout but i want to keep this as true for when the user is in the App so it remembers the state of the panel bar when they are not loggin out.

This is what i have got and have tried:

<

 

telerik:RadPanelBar id="panelbar" Runat="server" ExpandMode="SingleExpandedItem" AllowCollapseAllItems="true" OnClientItemClicked="PanelBarItemClicked" CookieName="TelerikRadPanelBarCookie" PersistStateInCookie="True" EnableEmbeddedSkins="False" Skin="CommuniGatorSkin">

 

 

</telerik:RadPanelBar>

 

 
Tried with no avail on log out.

Session(

"TelerikRadPanelBarCookie") = Nothing

 

Response.Cookies(

"TelerikRadPanelBarCookie").Expires = EmarketingDateTime.Now.AddYears(-30)

 


Also tried to set the items as selected as false in the Xml which i am generating dynamically but this too does not work.
Any ideas?

Thanks Aaron  

8 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 12 Oct 2009, 06:20 AM
Hello Aaron,

You can manually remove the cookie using the following code:

Page.ClientScript.RegisterStartupScript(GetType(), "DeleteCookie",  
  string.Format("document.cookie = \"{0}=;expires=\" + new Date().toGMTString() + \";path=/;\"; ",  
  RadPanelbar1.ClientID), true); 


Regards,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tonino
Top achievements
Rank 1
answered on 09 Feb 2010, 09:28 AM
Hi Paul

I've tried your code to clear the cookie, but it doesn't seem to work. I'm using VB and the 'classic' rad controls. Here the code that I'm using:
Private Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
   If Not IsPostBack Then 
      Dim strScriptName As String = "DeleteCookie" 
      Dim cstype As Type = Me.GetType() 
      If (Not Page.ClientScript.IsStartupScriptRegistered(cstype, strScriptName)) Then 
         Dim strScript As String = String.Format("document.cookie = ""{0}=;expires="" + new Date().toGMTString() + "";path=/;""; ", RadPanelbar1.ClientID) 
         Page.ClientScript.RegisterStartupScript(cstype, strScriptName, strScript, True
      End If 
   End If 
End Sub 

I'm using the code inside a user control.

Thanks for looking at it.

Tonino.
0
Peter
Telerik team
answered on 12 Feb 2010, 10:13 AM
Hello Tonino,

You can clear the value of the RadPanelbar state cookie upon logging out:
Protected Sub LogoutButton_Click(sender As Object, e As EventArgs)
    If Page.Request.Cookies("TelerikRadPanelBarCookie") <> Nothing Then
        Page.Request.Cookies("TelerikRadPanelBarCookie").Value = Nothing
    End If
End Sub

Let me know if this helps.


Greetings,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tonino
Top achievements
Rank 1
answered on 12 Feb 2010, 12:12 PM
Hi Peter!

Thanks for answering!

I tried your suggestion, but there is no "TelerikRadPanelBarCookie" cookie in the page request, see attached picture. There is a cookie named "pnlTop_p2_p0_AlarmMsgControl_msgPB" that looks like the one I need to reset, but resetting that one doesn't help either.
After resetting this cookie the panels are still expanded and the content of the cookie are set again.

Any other idea?

Tonino.
0
T. Tsonev
Telerik team
answered on 18 Feb 2010, 08:13 AM
Hi Tonino,

Indeed the cookie is not named "TelerikRadPanelBarCookie". It name matches the ClientID of the control.

The proper way to delete a cookie seems to be to set a past expires date:

http://msdn.microsoft.com/en-us/library/ms178195.aspx

Putting those two together we get:

Dim cookieName As String = msgPB.ClientID
 
If (Not Request.Cookies(cookieName) Is Nothing) Then
    Dim myCookie As HttpCookie
    myCookie = New HttpCookie(cookieName)
    myCookie.Expires = DateTime.Now.AddDays(-1D)
    Response.Cookies.Add(myCookie)
End If

I hope this helps.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tonino
Top achievements
Rank 1
answered on 18 Feb 2010, 03:14 PM
Thanks a lot Tsvetomir Tsonev!
It's working as expected now!
0
SA
Top achievements
Rank 1
answered on 07 Mar 2012, 11:30 PM
I'm having exact same issue. I'm using RadPanelBar and every time I load the page in a new browser it persist the selection. I tried but didn't work. Can you help me to deselect menu item when the page loads in a new browser? Please see the following code that I'm using.

Scenario:
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Menu.aspx.vb"
Inherits="Telerik.Web.Examples.PanelBar.Functionality.PersistingStateInCookie.Menu" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server"></telerik:RadStyleSheetManager>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
      //Put your JavaScript code here.
  
        var scrollTop;
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
  
        function BeginRequestHandler(sender, args) {
            var elem = $get("Panel1");
            scrollTop = elem.scrollTop;
        }
  
        function EndRequestHandler(sender, args) {
            var elem = $get("Panel1");
            elem.scrollTop = scrollTop;
        }
  
        function pageLoad() {
            if (scrollTop) { return; }
            if (getCookie()) {
                $get("Panel1").scrollTop = getCookie();
            }
        }
  
        function pageUnload() {
            setCookie($get("Panel1").scrollTop);
        }
  
  
        function setCookie(cookieValue) {
            sVar = "scrollTop";
            //the expiration time
            var date = new Date();
            date.setTime(new Date().getTime() + (60 * 60 * 1000));
            theCookie = sVar + '=' + cookieValue + '; expires=' + date.oGMTString(); 
            document.cookie = theCookie;
        }
  
        function getCookie() {
            sVar = "scrollTop";
            cookies = document.cookie.split('; ');
            for (var i = 1; i <= cookies.length; i++) {
                if (cookies[i - 1].split('=')[0] == sVar) {
                    return cookies[i - 1].split('=')[1];
                }
            }
        }
         
        function setCookie(cookieValue)
        
            setCookie(cookieValue,"",-1); 
        }
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
        <div id="Panel1" style="FLOAT:left; width:192px; overflow-y:scroll; overflow-x:hidden;">
            <telerik:RadPanelBar
                ID="RadPanelBar1"
                Runat="server"
                PersistStateInCookie="True"
                OnPreRender="RadPanelBar1_PreRender"
                DataFieldID="NavigationID"
                DataSourceID="SqlDataSource1"
                DataTextField="NavigationName"
                DataNavigateUrlField="URL"
                DataFieldParentID="ParentID"
                Skin="Web20"
                Width="180px"
                height="400"
                PostBackUrl="~/Menu.aspx">
            </telerik:RadPanelBar>
        </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:CS %>" SelectCommand="Select * from Navigation">
    </asp:SqlDataSource>
    </form>
</body>
</html>
0
Dimitar Terziev
Telerik team
answered on 12 Mar 2012, 02:38 PM
Hello,

Please open a support ticket and provide a runnable sample reproducing the experienced problem so we could test and troubleshoot it locally.

All the best,
Dimitar Terziev
the Telerik team
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 their blog feed now.
Tags
PanelBar
Asked by
Aaron
Top achievements
Rank 1
Answers by
Paul
Telerik team
Tonino
Top achievements
Rank 1
Peter
Telerik team
T. Tsonev
Telerik team
SA
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or