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

Cookie in RadPanelBar

14 Answers 173 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Elango
Top achievements
Rank 1
Elango asked on 02 Dec 2008, 09:44 PM
Hi,
     I have a RadPanelbar with several RadPanelItem inside the panel bar in one aspx page. Each panel item can be expanded / collapsed. Assume the user works only one panel item and the rest is collapsed. When the user closes the browser and opens again it shows everything as expanded. I tried PersistStateInCookie as true and with unique CookieName for that panelbar. I just want to preserve the same state of the radpanel bar while it was closed. Is this possible? If so please let me know.

Regards,
Elango

14 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Dec 2008, 03:59 PM
Hello Elango,

PersistStateInCookie works with session cookies which means that the cookie is destroyed when the user closes the browser. In a word you cannot use PersistStateInCookie to achieve your requirement. A possible workaround is to keep tracking the expanded items in a cookie which is not destroyed after closing the window.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Elango
Top achievements
Rank 1
answered on 03 Dec 2008, 04:27 PM

Hi Albert,
          Thanks for your response. Do you have any samples which tracks the expanded item in cookies which is not destroyed? If you have anything that would be great.

 

Regards,

Elango

 

 

0
Paul
Telerik team
answered on 04 Dec 2008, 01:12 PM
Hi Elango,

Please find below a sample code snippet that can be used to override the expiration of the panelbar's cookie.

<script type="text/javascript">  
Telerik.Web.UI.RadPanelBar.prototype._persistState = function ()  
{  
    var cookieValue = "{";  
    if (this.get_selectedItem())  
    {  
        cookieValue += "\"SelectedItems\":" + this._selectedItemsJson + ",";  
    }  
    cookieValue += "\"ExpandedItems\":" + this._expandedItemsJson + "}";  
 
    var expires = new Date();  
    expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000)); //one year  
    document.cookie = this.get_cookieName() + "=" + cookieValue  + ";path=/;expires=" + expires.toGMTString();  
}  
</script> 


All the best,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CSoft
Top achievements
Rank 1
answered on 09 Dec 2008, 01:25 PM
Hi Paul,

So we can simply place the JavaScript code inside the relevant page/user control and this will automatically persist the cookie for a year?

No need to wire Rad Panel to JS?
0
Elango
Top achievements
Rank 1
answered on 11 Dec 2008, 07:36 PM
Thanks. I will try this and let you know.

Regards,
Elango
0
Elango
Top achievements
Rank 1
answered on 12 Dec 2008, 10:22 PM

Hi Paul,

        I just pasted this code to my js file and its not working and it throws me can't find Telerik..... And also i have few doubts. Even though if i add this code how this will be binded to the radpanelbar. As i have lot RadPanelBar and i want to persist this cookie only for one of the radpanelbar not the all panelbars. So how to make cookie enabled only for a specified radpanelbar in my project? Please let me know regarding this.

Regards,

Elango

0
Paul
Telerik team
answered on 22 Dec 2008, 11:26 AM
Hi Elango,

Please find below a sample code snippet that shows the needed approach.

<form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
    </telerik:RadScriptManager> 
 
    <script type="text/javascript">     
    var originalPersistState = Telerik.Web.UI.RadPanelBar.prototype._persistState;  
    Telerik.Web.UI.RadPanelBar.prototype._persistState = function test()     
    {     
        if(this.get_id() != "RadPanelBar1")  
        {  
            originalPersistState.apply(this, []);  
            return;  
        }  
      
        var cookieValue = "{";     
        if (this.get_selectedItem())     
        {     
            cookieValue += "\"SelectedItems\":" + this._selectedItemsJson + ",";     
        }     
        cookieValue += "\"ExpandedItems\":" + this._expandedItemsJson + "}";     
        
        var expires = new Date();     
        expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000)); //one year     
        document.cookie = this.get_cookieName() + "=" + cookieValue  + ";path=/;expires=" + expires.toGMTString();  
    }     
   
      
    </script> 
 
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Width="100%" PersistStateInCookie="True">  
        <CollapseAnimation Duration="100" Type="None" /> 
        <ExpandAnimation Duration="100" Type="None" /> 
        <Items> 
            <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1">  
                <Items> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 1">  
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 2">  
                        <Items> 
                            <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 1">  
                            </telerik:RadPanelItem> 
                            <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 2">  
                            </telerik:RadPanelItem> 
                        </Items> 
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 3">  
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 4">  
                    </telerik:RadPanelItem> 
                </Items> 
            </telerik:RadPanelItem> 
        </Items> 
    </telerik:RadPanelBar> 
    <telerik:RadPanelBar ID="RadPanelBar2" runat="server" Width="100%" PersistStateInCookie="True">  
        <CollapseAnimation Duration="100" Type="None" /> 
        <ExpandAnimation Duration="100" Type="None" /> 
        <Items> 
            <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1">  
                <Items> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 1">  
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 2">  
                        <Items> 
                            <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 1">  
                            </telerik:RadPanelItem> 
                            <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 2">  
                            </telerik:RadPanelItem> 
                        </Items> 
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 3">  
                    </telerik:RadPanelItem> 
                    <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 4">  
                    </telerik:RadPanelItem> 
                </Items> 
            </telerik:RadPanelItem> 
        </Items> 
    </telerik:RadPanelBar> 
</form> 


Greetings,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kyle Butler
Top achievements
Rank 2
answered on 05 Jan 2009, 08:26 PM
I'm recieving and error with this line of code Telerik.Web.UI.RadPanelBar.prototype._persistState = function test()  
I'm being told that the word "Telerik" is undefined. Also, I do not have access to the object RadScriptManager. Is there any other way of making the PersistStateCookie not terminate on browser close?

Thanks!


0
Elango
Top achievements
Rank 1
answered on 06 Jan 2009, 05:15 PM
Paul,
     I tried your solution but it throws "Telerik" is undefined (javascript error). Also i am using asp script manager. I am not sure what could solve this? Please do let me know.

Regards,
Elango
0
Atanas Korchev
Telerik team
answered on 06 Jan 2009, 05:20 PM
Hi Elango,

You need to paste the script block after the panelbar declaration.

Best wishes,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kyle Butler
Top achievements
Rank 2
answered on 15 Jan 2009, 09:11 PM
I tried putting th script after the panel bar but I'm still getting told that Telerik is undefined. Any help here?
0
Atanas Korchev
Telerik team
answered on 16 Jan 2009, 07:43 AM
Hi Kyle Butler,

Please paste here the code of your page.

Best wishes,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kyle Butler
Top achievements
Rank 2
answered on 16 Jan 2009, 01:38 PM
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">  
    <uc1:MenuControl ID="Test1" runat="server" /> 
 <fieldset id = "bodyFieldset">     
 <fieldset> 
  <table width="100%">  
    <tr> 
        <td width="25%">  
            <asp:Label ID="lblEmail1" runat="server" Text="Email: " Font-Size="Small"></asp:Label> 
            <asp:Label ID="lblEmail" runat="server" Text="Not Available"   
                Font-Underline="True" Font-Bold="True" ForeColor="#003399" Font-Size="Small"></asp:Label> 
        </td> 
        <td align="center">  
            <asp:Label ID="lblPerm1" runat="server" Text="User Permissions: "   
                Font-Size="Small"></asp:Label> 
            <asp:Label ID="lblPerm" runat="server"   
                Font-Underline="True"  Font-Bold="True" ForeColor="#003399"   
                Font-Size="Small"></asp:Label> 
        </td> 
        <td align="right" width="25%">  
            <asp:Label ID="Label1" runat="server" Text="Max Approval Amount:"   
                Font-Size="Small"></asp:Label> 
            <asp:Label ID="lblThreshold" runat="server"   
                Font-Underline="True"  Font-Bold="True" ForeColor="#003399"   
                Font-Size="Small"></asp:Label> 
        </td> 
    </tr> 
 </table> 
   
 <table> 
    <tr> 
        <td align="center">  
            <br /> 
            <rad:radpanelbar runat="server" ID="mnuMain" Skin="Default2006"   
                Width="100%" Font-Size="Large" CausesValidation="False"   
                PersistStateInCookie="True">  
                <collapseanimation type="Linear" /> 
                <expandanimation type="Linear" /> 
                <Items> 
                    <rad:RadPanelItem runat="server" Text="Processing" Expanded="True">  
                        <Items> 
                            <rad:RadPanelItem runat="server" NavigateUrl="~/APApprovalsv2/APEntryPage.aspx"   
                            Text="Enter New Invoice" Value="btnEntry" Visible="False"   
                                ToolTip="Enter a new invoice.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APNewVendorList.aspx" Text="New Vendor List"   
                            Value="btnNewVendorList" Visible="False"   
                                ToolTip="Approve invoices with new vendors.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APPendingApprovalList.aspx" Text="Approvals List"   
                            Value="btnApprovals" Visible="False" ToolTip="Check &amp; approve invoices.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                                NavigateUrl="~/APApprovalsv2/APPendingCFOApprovalList.aspx"   
                                Text="CFO Approvals List"   
                                ToolTip="Approve CFO flagged invoices from this list." Value="btnCFO"   
                                Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APPendingReviewList.aspx" Text="Reviews List"   
                            Value="btnReviews" Visible="False" ToolTip="Review invoices for dataporting.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APRejectList.aspx" Text="Rejected List"   
                            Value="btnRejected" Visible="False"   
                                ToolTip="Restore or cancel rejected invoices.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APDataportList.aspx" Text="Dataport Page"   
                            Value="btnDataport" Visible="False" ToolTip="Dataport invoices into navision.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APDataportReceiptList.aspx"   
                            Text="Dataport Receipts Page" Value="btnRecDataport" Visible="False"   
                                ToolTip="Dataport Receipts into navision.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APCheckRunVerification.aspx"   
                            Text="Check Run Verification" Value="btnCheckRun" Visible="False"   
                                ToolTip="Verify invoices with or without CAR #s.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server">  
                            </rad:RadPanelItem> 
                        </Items> 
                    </rad:RadPanelItem> 
                    <rad:RadPanelItem runat="server" Text="Lookup / Searching" Expanded="True"   
                        Value="LookupSearch" Visible="False">  
                        <Items> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APRecentScanList.aspx"   
                            Text="Recently Scanned List" Value="btnScanned" Visible="False"   
                                ToolTip="View recently scanned invoices.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APInvoiceHistory.aspx" Text="Invoice History"   
                            Value="btnInvoiceHistory" Visible="False"   
                                ToolTip="View invoices that users have processed.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APDelinquencyReport.aspx"   
                            Text="Delinquency Report" Value="btnDelinquency" Visible="False"   
                                ToolTip="View invoices older than a specified date.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                                NavigateUrl="~/APApprovalsv2/APInvoiceByBranchReport.aspx"   
                                Text="Invoice By Branch Report" ToolTip="View invoices by branch and date"   
                                Value="btnByBranch" Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                                NavigateUrl="~/APApprovalsv2/APInvoiceReport.aspx"   
                                Text="Invoices By Company Report" ToolTip="View invoices by company and date"   
                                Value="btnInvoiceReport" Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server">  
                            </rad:RadPanelItem> 
                        </Items> 
                    </rad:RadPanelItem> 
                    <rad:RadPanelItem runat="server" Text="User Options" Expanded="True">  
                        <Items> 
                            <rad:RadPanelItem runat="server" Text="User Options" Value="btnUserAdmin"   
                                ToolTip="Maintian your user options.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APActivityLog.aspx" Text="User Activity Log"   
                            Value="btnLog" ToolTip="Review your activity within the AP System.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/apuserdefaultglaccount.aspx"   
                            Text="User Default GL Account List" Value="btnUserDefaultGLAccount"   
                            Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/apglaccountsdefaultapprovers.aspx"   
                            Text="Default Approvers List" Value="btnDefaultApprovers" Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/apuseridmapping.aspx" Text="User Id Mapping"   
                                Value="btnUserIDMapping" Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server">  
                            </rad:RadPanelItem> 
                        </Items> 
                    </rad:RadPanelItem> 
                    <rad:RadPanelItem runat="server" Expanded="True" Text="Administration"   
                    Value="Administration" Visible="False">  
                        <Items> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APAdministrativePage.aspx" Text="Admin Users List"   
                            Value="btnAdmin" Visible="False" ToolTip="Maintian all AP users.">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                            NavigateUrl="~/APApprovalsv2/APAdminForwarding.aspx"   
                            Text="Admin Invoice Forwarding" Value="btnAdminForwarding" Visible="False">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server"   
                                NavigateUrl="~/APApprovalsv2/APSpecialCaseAdministration.aspx"   
                                Text="Special Case Administration" Value="btnSCAdmin">  
                            </rad:RadPanelItem> 
                            <rad:RadPanelItem runat="server">  
                            </rad:RadPanelItem> 
                        </Items> 
                    </rad:RadPanelItem> 
                    <rad:RadPanelItem runat="server" Expanded="True" Text="Help">  
                        <Items> 
                            <rad:RadPanelItem runat="server" NavigateUrl="~/APApprovalsv2/APHelpPage.aspx"   
                            Text="The AP Help Guide" ImageOverUrl="~/images/WORD3_12x12.jpg"   
                                ToolTip="View the help guide on the AP System.">  
                            </rad:RadPanelItem> 
                        </Items> 
                    </rad:RadPanelItem> 
                </Items> 
            </rad:radpanelbar> 
        </td> 
    </tr> 
 </table> 
</fieldset> 
</fieldset> 
 
   
    <script type="text/javascript">        
    var originalPersistState = Telerik.Web.UI.RadPanelBar.prototype._persistState;     
    Telerik.Web.UI.RadPanelBar.prototype._persistState = function test()        
    {        
        if(this.get_id() != "RadPanelBar1")     
        {     
            originalPersistState.apply(this, []);     
            return;     
        }     
         
        var cookieValue = "{";        
        if (this.get_selectedItem())        
        {        
            cookieValue += "\"SelectedItems\":" + this._selectedItemsJson + ",";        
        }        
        cookieValue += "\"ExpandedItems\":" + this._expandedItemsJson + "}";        
           
        var expires = new Date();        
        expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000)); //one year        
        document.cookie = this.get_cookieName() + "=" + cookieValue  + ";path=/;expires=" + expires.toGMTString();     
    }       
   </script>   
 
</asp:Content> 
0
Atanas Korchev
Telerik team
answered on 16 Jan 2009, 01:56 PM
Hello Kyle Butler,

The solution posted here is for RadPanelBar for ASP.NET Ajax. You are using RadPanelBar classic which does not support the requested capability.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
PanelBar
Asked by
Elango
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Elango
Top achievements
Rank 1
Paul
Telerik team
CSoft
Top achievements
Rank 1
Kyle Butler
Top achievements
Rank 2
Share this question
or