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

Selecting RadPanelItem in code-behind with PersistStateInCookie doesn't work

9 Answers 256 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
James Steward
Top achievements
Rank 1
James Steward asked on 08 Dec 2009, 08:39 PM
Hi,
This seems like a bug to me. I'm trying to persist the state of my RadPanelBar using PersistStateInCookie, which works fine if I'm only updating the RadPanelBar by itself. However, if I try to update the RadPanelBar via another control on the page, like the click event in code-behind of a button, it doesn't work.
I understand from doing a little research that the cookie resets the state of the RadPanelBar in (or possibly just before) the PreRender event of the RadPanelBar control. This means that it will always overwrite the selection of a RadPanelItem by another control on the page.

Here is an example of what I'm talking about:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" /> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        <Scripts> 
            <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" /> 
        </Scripts> 
    </telerik:RadScriptManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="LoadingPanel1">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="dCurrentPage">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="dCurrentPage" /> 
                    <telerik:AjaxUpdatedControl ControlID="btnSelectPanel" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadPanelBar1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadPanelBar1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="dCurrentPage" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadPanelBar1" /> 
                    <telerik:AjaxUpdatedControl ControlID="btnSelectPanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
      
      
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" Transparency="30" 
        BackColor="#E0E0E0">  
        <img src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
            alt="Loading..." style="border: 0;" /> 
    </telerik:RadAjaxLoadingPanel> 
    <div style="float: left; margin-bottom: 10px; width: 270px">  
        <telerik:RadPanelBar runat="server" ID="RadPanelBar1" PersistStateInCookie="True" 
            OnPreRender="RadPanelBar1_PreRender">  
            <Items> 
                <telerik:RadPanelItem Text="ASP.NET controls" Expanded="true">  
                    <Items> 
                        <telerik:RadPanelItem NavigateUrl="Default.aspx?page=menu" Text="RadMenu">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem NavigateUrl="Default.aspx?page=combobox" Text="RadComboBox">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem NavigateUrl="Default.aspx?page=panelbar" Text="RadPanelBar">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem NavigateUrl="Default.aspx?page=treeview" Text="RadTreeView">  
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
                <telerik:RadPanelItem Text="WinForms controls">  
                    <Items> 
                        <telerik:RadPanelItem Text="RadMenustrip" NavigateUrl="Default.aspx?page=menustrip">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="RadTabStrip" NavigateUrl="Default.aspx?page=tabstrip">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="RadToolStrip" NavigateUrl="Default.aspx?page=toolbarstrip">  
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
                <telerik:RadPanelItem Text="Other projects">  
                    <Items> 
                        <telerik:RadPanelItem Text="SiteFinity" NavigateUrl="Default.aspx?page=sitefinity">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="Reporting" NavigateUrl="Default.aspx?page=reporting">  
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="RadAjax" NavigateUrl="Default.aspx?page=ajax">  
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelBar> 
    </div> 
    <div class="smallModule" id="dCurrentPage" runat="server">  
        <div class="rc1">  
            <div class="rc2">  
                <div class="rc3">  
                    <strong>Current page:</strong> 
                    <style="padding: 5px 10px">  
                        <asp:Literal runat="server" ID="Label1"></asp:Literal></p>  
                </div> 
            </div> 
        </div> 
    </div> 
    <br /> 
    <div style="display:block">  
        <asp:Button ID="btnSelectPanel" runat="server" Text="Select RadTabStrip" OnClick="btnSelectPanel_Click" /><br /> 
        <href="Default2.aspx">Go to Default2.aspx</a> 
    </div> 
    </form> 
</body> 
</html> 
 

Default.aspx.cs
using System;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
 
using System.Data;  
using System.Configuration;  
using System.Web.Security;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using Telerik.Web.UI;  
 
public partial class Default : System.Web.UI.Page   
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        Response.Cache.SetCacheability(HttpCacheability.NoCache);  
              
    }  
 
    protected void RadPanelBar1_PreRender(object sender, EventArgs e)  
    {  
        RadPanelItem selectedItem = RadPanelBar1.SelectedItem;  
        if (selectedItem != null)  
        {  
            Label1.Text = String.Format("This is the {0} page", selectedItem.Text);  
        }  
    }  
 
    protected void btnSelectPanel_Click(object sender, EventArgs e)  
    {  
        RadPanelItem item = RadPanelBar1.FindItemByText("RadTabStrip");  
        RadPanelItem owner = item.Owner as RadPanelItem;  
        owner.Expanded = true;  
        item.Selected = true;  
    }  
}  
 

Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
    This is another page.<br /> 
        <href="Default.aspx">Go back to Default.aspx</a> 
    </div> 
    </form> 
</body> 
</html> 
 

If you select an item in the RadPanelBar, then click on the link to Go to Default2.aspx, then go back to the Default.aspx page you will see that the state has been maintained. However, if you click the button to select the "RadTabStrip" item in the RadPanelBar you will see that it does not work.
If you change PersistStateInCookie to False, clicking on the button does work, but obviously the the state is not maintained.

I'm sure there is a workaround for this, but it seems to me that it breaks the coding convention of the Page event lifecycle.
Any thoughts?

James Steward

9 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 15 Dec 2009, 11:53 AM
Hi James Steward,

Thank you for reporting this issue.

It is indeed a bug, so I logged it in our bug-tracking system and updated your Telerik points.

We will fix the issue in the upcoming weeks.

Kind regards,
Simon
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
Brian Cumberledge
Top achievements
Rank 1
answered on 24 Feb 2010, 05:07 PM
Has this been fixed?
When I navigate back to the page that has the radPanel, I want to run server side code for the selected radpanelitem.  It always seems to be null on page load.

RadPanelBar1.SelectedItem.Value

If fixed, at what point can I get the above value?   Thanks.

0
Simon
Telerik team
answered on 08 Mar 2010, 03:56 PM
Hello Brian Cumberledge,

The issue is still pending.

Please use our Public Issue Tracking System to follow its status and/or vote for it to increase its importance, so that we fix it sooner.

All the best,
Simon
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
Andy
Top achievements
Rank 1
answered on 03 Feb 2011, 10:53 AM
Hi,

Has this issue been fixed? We are having trouble with this

Thanks
Andy
0
Yana
Telerik team
answered on 03 Feb 2011, 11:34 AM
Hello Andy,

I'm afraid that this issue is not resolved yet.

All the best,
Yana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Yogesh
Top achievements
Rank 1
answered on 18 Jul 2012, 08:49 AM
Hi Team,

      Do we have any update on this issue now?

Thanks,
Yogesh.
0
Kate
Telerik team
answered on 20 Jul 2012, 07:59 AM
Hi Yogesh,

I checked the issue in both the PITS (http://www.telerik.com/support/pits.aspx#/public/aspnet-ajax/232) and our internal system and as indicated in its status it is already resolved. Please give it a try with any version after Q2 2011 of the Telerik controls and let me know if you encounter any issues.

All the best,
Kate
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.
0
Carlos
Top achievements
Rank 1
answered on 28 May 2015, 06:06 PM
I am using latest version. its stil not working in the item click event if I set NavigateUrl.
0
Nencho
Telerik team
answered on 02 Jun 2015, 12:33 PM
Hello James,

I am afraid that after some further consideration of this behavior, we determine that this is the proper one, because the item navigate to the particular URL rather than posting back to the current page. Please refer to the documentation article below, where it is demonstrated the approach that we suggest to use in such scenario (using the Attributes collection of the Items). The article is in regards to the RadMenu, however the same could be applied on the RadPanelBar:

http://www.telerik.com/help/aspnet-ajax/menu-itemclick-event-not-fired.html

Please consider the below implementation:
<telerik:RadPanelBar runat="server" ID="RadPanelBar1 OnItemClick="RadPanelBar1_ItemClick">
               <Items>
                   <telerik:RadPanelItem Text="Item 1">
                       <Items>
                           <telerik:RadPanelItem Text="Item 1.1" CustomNavigateUrl="http://www.google.com">
                           </telerik:RadPanelItem>
.............................

protected void RadPanelBar1_ItemClick(object sender, RadPanelBarEventArgs e)
   {
       Response.Redirect(e.Item.Attributes["CustomNavigateUrl"].ToString()); 
   }


Regards,
Nencho
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
PanelBar
Asked by
James Steward
Top achievements
Rank 1
Answers by
Simon
Telerik team
Brian Cumberledge
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Yana
Telerik team
Yogesh
Top achievements
Rank 1
Kate
Telerik team
Carlos
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or