Cookie in RadPanelBar

15 posts, 0 answers
  1. Elango
    Elango avatar
    29 posts
    Member since:
    Jul 2008

    Posted 02 Dec 2008 Link to this post

    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
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 03 Dec 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Elango
    Elango avatar
    29 posts
    Member since:
    Jul 2008

    Posted 03 Dec 2008 Link to this post

    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

     

     

  5. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 04 Dec 2008 Link to this post

    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.
  6. CSoft
    CSoft avatar
    4 posts
    Member since:
    Aug 2005

    Posted 09 Dec 2008 Link to this post

    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?
  7. Elango
    Elango avatar
    29 posts
    Member since:
    Jul 2008

    Posted 11 Dec 2008 Link to this post

    Thanks. I will try this and let you know.

    Regards,
    Elango
  8. Elango
    Elango avatar
    29 posts
    Member since:
    Jul 2008

    Posted 12 Dec 2008 Link to this post

    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

  9. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 22 Dec 2008 Link to this post

    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.
  10. Kyle Butler
    Kyle Butler avatar
    26 posts
    Member since:
    Jun 2008

    Posted 05 Jan 2009 Link to this post

    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!


  11. Elango
    Elango avatar
    29 posts
    Member since:
    Jul 2008

    Posted 06 Jan 2009 Link to this post

    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
  12. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 06 Jan 2009 Link to this post

    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.
  13. Kyle Butler
    Kyle Butler avatar
    26 posts
    Member since:
    Jun 2008

    Posted 15 Jan 2009 Link to this post

    I tried putting th script after the panel bar but I'm still getting told that Telerik is undefined. Any help here?
  14. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 16 Jan 2009 Link to this post

    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.
  15. Kyle Butler
    Kyle Butler avatar
    26 posts
    Member since:
    Jun 2008

    Posted 16 Jan 2009 Link to this post

    1 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">  
    2     <uc1:MenuControl ID="Test1" runat="server" /> 
    3  <fieldset id = "bodyFieldset">     
    4  <fieldset> 
    5   <table width="100%">  
    6     <tr> 
    7         <td width="25%">  
    8             <asp:Label ID="lblEmail1" runat="server" Text="Email: " Font-Size="Small"></asp:Label> 
    9             <asp:Label ID="lblEmail" runat="server" Text="Not Available"   
    10                 Font-Underline="True" Font-Bold="True" ForeColor="#003399" Font-Size="Small"></asp:Label> 
    11         </td> 
    12         <td align="center">  
    13             <asp:Label ID="lblPerm1" runat="server" Text="User Permissions: "   
    14                 Font-Size="Small"></asp:Label> 
    15             <asp:Label ID="lblPerm" runat="server"   
    16                 Font-Underline="True"  Font-Bold="True" ForeColor="#003399"   
    17                 Font-Size="Small"></asp:Label> 
    18         </td> 
    19         <td align="right" width="25%">  
    20             <asp:Label ID="Label1" runat="server" Text="Max Approval Amount:"   
    21                 Font-Size="Small"></asp:Label> 
    22             <asp:Label ID="lblThreshold" runat="server"   
    23                 Font-Underline="True"  Font-Bold="True" ForeColor="#003399"   
    24                 Font-Size="Small"></asp:Label> 
    25         </td> 
    26     </tr> 
    27  </table> 
    28    
    29  <table> 
    30     <tr> 
    31         <td align="center">  
    32             <br /> 
    33             <rad:radpanelbar runat="server" ID="mnuMain" Skin="Default2006"   
    34                 Width="100%" Font-Size="Large" CausesValidation="False"   
    35                 PersistStateInCookie="True">  
    36                 <collapseanimation type="Linear" /> 
    37                 <expandanimation type="Linear" /> 
    38                 <Items> 
    39                     <rad:RadPanelItem runat="server" Text="Processing" Expanded="True">  
    40                         <Items> 
    41                             <rad:RadPanelItem runat="server" NavigateUrl="~/APApprovalsv2/APEntryPage.aspx"   
    42                             Text="Enter New Invoice" Value="btnEntry" Visible="False"   
    43                                 ToolTip="Enter a new invoice.">  
    44                             </rad:RadPanelItem> 
    45                             <rad:RadPanelItem runat="server"   
    46                             NavigateUrl="~/APApprovalsv2/APNewVendorList.aspx" Text="New Vendor List"   
    47                             Value="btnNewVendorList" Visible="False"   
    48                                 ToolTip="Approve invoices with new vendors.">  
    49                             </rad:RadPanelItem> 
    50                             <rad:RadPanelItem runat="server"   
    51                             NavigateUrl="~/APApprovalsv2/APPendingApprovalList.aspx" Text="Approvals List"   
    52                             Value="btnApprovals" Visible="False" ToolTip="Check &amp; approve invoices.">  
    53                             </rad:RadPanelItem> 
    54                             <rad:RadPanelItem runat="server"   
    55                                 NavigateUrl="~/APApprovalsv2/APPendingCFOApprovalList.aspx"   
    56                                 Text="CFO Approvals List"   
    57                                 ToolTip="Approve CFO flagged invoices from this list." Value="btnCFO"   
    58                                 Visible="False">  
    59                             </rad:RadPanelItem> 
    60                             <rad:RadPanelItem runat="server"   
    61                             NavigateUrl="~/APApprovalsv2/APPendingReviewList.aspx" Text="Reviews List"   
    62                             Value="btnReviews" Visible="False" ToolTip="Review invoices for dataporting.">  
    63                             </rad:RadPanelItem> 
    64                             <rad:RadPanelItem runat="server"   
    65                             NavigateUrl="~/APApprovalsv2/APRejectList.aspx" Text="Rejected List"   
    66                             Value="btnRejected" Visible="False"   
    67                                 ToolTip="Restore or cancel rejected invoices.">  
    68                             </rad:RadPanelItem> 
    69                             <rad:RadPanelItem runat="server"   
    70                             NavigateUrl="~/APApprovalsv2/APDataportList.aspx" Text="Dataport Page"   
    71                             Value="btnDataport" Visible="False" ToolTip="Dataport invoices into navision.">  
    72                             </rad:RadPanelItem> 
    73                             <rad:RadPanelItem runat="server"   
    74                             NavigateUrl="~/APApprovalsv2/APDataportReceiptList.aspx"   
    75                             Text="Dataport Receipts Page" Value="btnRecDataport" Visible="False"   
    76                                 ToolTip="Dataport Receipts into navision.">  
    77                             </rad:RadPanelItem> 
    78                             <rad:RadPanelItem runat="server"   
    79                             NavigateUrl="~/APApprovalsv2/APCheckRunVerification.aspx"   
    80                             Text="Check Run Verification" Value="btnCheckRun" Visible="False"   
    81                                 ToolTip="Verify invoices with or without CAR #s.">  
    82                             </rad:RadPanelItem> 
    83                             <rad:RadPanelItem runat="server">  
    84                             </rad:RadPanelItem> 
    85                         </Items> 
    86                     </rad:RadPanelItem> 
    87                     <rad:RadPanelItem runat="server" Text="Lookup / Searching" Expanded="True"   
    88                         Value="LookupSearch" Visible="False">  
    89                         <Items> 
    90                             <rad:RadPanelItem runat="server"   
    91                             NavigateUrl="~/APApprovalsv2/APRecentScanList.aspx"   
    92                             Text="Recently Scanned List" Value="btnScanned" Visible="False"   
    93                                 ToolTip="View recently scanned invoices.">  
    94                             </rad:RadPanelItem> 
    95                             <rad:RadPanelItem runat="server"   
    96                             NavigateUrl="~/APApprovalsv2/APInvoiceHistory.aspx" Text="Invoice History"   
    97                             Value="btnInvoiceHistory" Visible="False"   
    98                                 ToolTip="View invoices that users have processed.">  
    99                             </rad:RadPanelItem> 
    100                             <rad:RadPanelItem runat="server"   
    101                             NavigateUrl="~/APApprovalsv2/APDelinquencyReport.aspx"   
    102                             Text="Delinquency Report" Value="btnDelinquency" Visible="False"   
    103                                 ToolTip="View invoices older than a specified date.">  
    104                             </rad:RadPanelItem> 
    105                             <rad:RadPanelItem runat="server"   
    106                                 NavigateUrl="~/APApprovalsv2/APInvoiceByBranchReport.aspx"   
    107                                 Text="Invoice By Branch Report" ToolTip="View invoices by branch and date"   
    108                                 Value="btnByBranch" Visible="False">  
    109                             </rad:RadPanelItem> 
    110                             <rad:RadPanelItem runat="server"   
    111                                 NavigateUrl="~/APApprovalsv2/APInvoiceReport.aspx"   
    112                                 Text="Invoices By Company Report" ToolTip="View invoices by company and date"   
    113                                 Value="btnInvoiceReport" Visible="False">  
    114                             </rad:RadPanelItem> 
    115                             <rad:RadPanelItem runat="server">  
    116                             </rad:RadPanelItem> 
    117                         </Items> 
    118                     </rad:RadPanelItem> 
    119                     <rad:RadPanelItem runat="server" Text="User Options" Expanded="True">  
    120                         <Items> 
    121                             <rad:RadPanelItem runat="server" Text="User Options" Value="btnUserAdmin"   
    122                                 ToolTip="Maintian your user options.">  
    123                             </rad:RadPanelItem> 
    124                             <rad:RadPanelItem runat="server"   
    125                             NavigateUrl="~/APApprovalsv2/APActivityLog.aspx" Text="User Activity Log"   
    126                             Value="btnLog" ToolTip="Review your activity within the AP System.">  
    127                             </rad:RadPanelItem> 
    128                             <rad:RadPanelItem runat="server"   
    129                             NavigateUrl="~/APApprovalsv2/apuserdefaultglaccount.aspx"   
    130                             Text="User Default GL Account List" Value="btnUserDefaultGLAccount"   
    131                             Visible="False">  
    132                             </rad:RadPanelItem> 
    133                             <rad:RadPanelItem runat="server"   
    134                             NavigateUrl="~/APApprovalsv2/apglaccountsdefaultapprovers.aspx"   
    135                             Text="Default Approvers List" Value="btnDefaultApprovers" Visible="False">  
    136                             </rad:RadPanelItem> 
    137                             <rad:RadPanelItem runat="server"   
    138                             NavigateUrl="~/APApprovalsv2/apuseridmapping.aspx" Text="User Id Mapping"   
    139                                 Value="btnUserIDMapping" Visible="False">  
    140                             </rad:RadPanelItem> 
    141                             <rad:RadPanelItem runat="server">  
    142                             </rad:RadPanelItem> 
    143                         </Items> 
    144                     </rad:RadPanelItem> 
    145                     <rad:RadPanelItem runat="server" Expanded="True" Text="Administration"   
    146                     Value="Administration" Visible="False">  
    147                         <Items> 
    148                             <rad:RadPanelItem runat="server"   
    149                             NavigateUrl="~/APApprovalsv2/APAdministrativePage.aspx" Text="Admin Users List"   
    150                             Value="btnAdmin" Visible="False" ToolTip="Maintian all AP users.">  
    151                             </rad:RadPanelItem> 
    152                             <rad:RadPanelItem runat="server"   
    153                             NavigateUrl="~/APApprovalsv2/APAdminForwarding.aspx"   
    154                             Text="Admin Invoice Forwarding" Value="btnAdminForwarding" Visible="False">  
    155                             </rad:RadPanelItem> 
    156                             <rad:RadPanelItem runat="server"   
    157                                 NavigateUrl="~/APApprovalsv2/APSpecialCaseAdministration.aspx"   
    158                                 Text="Special Case Administration" Value="btnSCAdmin">  
    159                             </rad:RadPanelItem> 
    160                             <rad:RadPanelItem runat="server">  
    161                             </rad:RadPanelItem> 
    162                         </Items> 
    163                     </rad:RadPanelItem> 
    164                     <rad:RadPanelItem runat="server" Expanded="True" Text="Help">  
    165                         <Items> 
    166                             <rad:RadPanelItem runat="server" NavigateUrl="~/APApprovalsv2/APHelpPage.aspx"   
    167                             Text="The AP Help Guide" ImageOverUrl="~/images/WORD3_12x12.jpg"   
    168                                 ToolTip="View the help guide on the AP System.">  
    169                             </rad:RadPanelItem> 
    170                         </Items> 
    171                     </rad:RadPanelItem> 
    172                 </Items> 
    173             </rad:radpanelbar> 
    174         </td> 
    175     </tr> 
    176  </table> 
    177 </fieldset> 
    178 </fieldset> 
    179  
    180    
    181     <script type="text/javascript">        
    182     var originalPersistState = Telerik.Web.UI.RadPanelBar.prototype._persistState;     
    183     Telerik.Web.UI.RadPanelBar.prototype._persistState = function test()        
    184     {        
    185         if(this.get_id() != "RadPanelBar1")     
    186         {     
    187             originalPersistState.apply(this, []);     
    188             return;     
    189         }     
    190          
    191         var cookieValue = "{";        
    192         if (this.get_selectedItem())        
    193         {        
    194             cookieValue += "\"SelectedItems\":" + this._selectedItemsJson + ",";        
    195         }        
    196         cookieValue += "\"ExpandedItems\":" + this._expandedItemsJson + "}";        
    197            
    198         var expires = new Date();        
    199         expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000)); //one year        
    200         document.cookie = this.get_cookieName() + "=" + cookieValue  + ";path=/;expires=" + expires.toGMTString();     
    201     }       
    202    </script>   
    203  
    204 </asp:Content> 
  16. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 16 Jan 2009 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017