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

Parent panelitem instantly deselects before postback

5 Answers 107 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Feb 2009, 12:25 AM
Hello,

I pull out a list of menu items to databind to the panelbar control (only 2 levels deep). In the code's ItemDataBound event I evaluate the current browser URL and then compare it to the URL for the current panelbar item - if it's a match, I select the item (and if it's a child item the parent is automatically selected as well by the panelbar control, apparently). Now to my problem...

When I click a child element in the panelbar, the parent element is instantly deselected then the postback occurs and the parent and child elements are selected again (as I reselect them in code). With the non-ajax version of this control in the older rad controls suite this did not occur. Instead I would click the child element and the parent element would stay selected, the postback would occur and I would reselect both in the code before returning the response with both parent and child selected.

Is there some kind of property I can set to turn off this instant client-side reaction that causes the parent panel item to become deselected? I don't know why the control behavior is different from the original non-ajax one.

Thanks,
Chris

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Feb 2009, 03:02 PM
Hello Chris,

We couldn't reproduce such behavior in our online demos:
http://demos.telerik.com/aspnet-ajax/panelbar/examples/functionality/persiststateincookie/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/panelbar/examples/applicationscenarios/persistingstate/defaultcs.aspx?page=toolbarstrip

Are you using the PersistStateInCookie property?

Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chris
Top achievements
Rank 1
answered on 23 Feb 2009, 07:59 PM
No, I'm not using that property and when I tried enabling it it didn't solve the problem.

I essentially just bind a list of panelbar items on the first page load (within a master page), compare the current url path to every one of the radpanelbar items I'm about to databind, make note if there was a match, then proceed to the radpanelbar's ItemDataBound property. It's there that I manually select the appropriate panelbar based on the current URL.

So, to reiterate, the problem with the new ajax version of the radpanelbar is that when I select a panelbar item and it causes a postback (or maybe directly links to the page with an html link...not sure how the RadPanelBar navigates to it's URL), but immediately after I click the RadPanelBar item, whatever item was selected is instantly deselected (something on the client-side apparently) while the browser starts to navigate to the new page. Once the new page is loaded/redrawn all the proper RadPanelBar items are selected. The difference between the old and ajax radpanelbar item is that the old one didn't have this instant client-side de-select when the panelbar was clicked.

On to the code...which when I copied and pasted into this post looks quite bad. Please just copy and paste the code into Visual Studio and it hopefully should be much easier to read!

I have my radpanel defined like so:

<

 

telerik:radpanelbar id="RadPanelBar2" runat="server" skin="Outlook" Width="175px" Height="89%" style="max-height:710px;" ExpandMode="FullExpandedItem" >

 

 

 

 

 

 

    <CollapseAnimation Type="None" Duration="100"></CollapseAnimation>

 

 

 

 

 

 

    <ExpandAnimation Type="None" Duration="100"></ExpandAnimation>

 

 

 

 

 

 

</telerik:radpanelbar>

Nothing to complicated and the items are loaded from a database the first time the master page loads.

Here is my code for handling databinding and which panelbar is selected based on the currently detected URL (as the url must match up with a panelbar's url for an item to appear selected). This code may be a bit 'quirky'/messy, but it got me the behavior I wanted with the original non-ajax panelbar.

1) First here is the code that binds the panelbar on the first page_load only (so in page_load's --- if me.ispostback = false):

 

Private Su

 

b LoadMenuItems()

 

 

    'Format current browser's URL to compare to RadPanelbar's URL
    Dim
lVirRootDir As String = Request.ApplicationPath.ToLower 

 

 

    Dim lURL As String = Request.FilePath.ToLower.Replace(lVirRootDir & "/", "")

 

 

    '--------------------------------------------------------------

 

    'Load User's Allowed Menu Items

 

    '--------------------------------------------------------------  

 

    'TODO Telerik: For testing purposes, create a typical example datatable for binding to the RadPanelbar

    Dim lDT As New DataTable

 

 

    Dim lFound As Boolean = False 
 

    'Check For Current URL (in user's browser address bar) in datatable

 

    For Each lRow As DataRow In lDT.Select("PAGE_URL='" & lURL & "'"
        lFound =
True 'If found, in the ItemDataBound we'll select the RadPanelBar item that matches the current url

 

    Next

 

 

 

 

    'Used later in RadPanel ItemDataBound event
    ViewState("

MenuURLDetected") = lFound 

 

 

 

    RadPanelBar2.DataSource = lDT

    RadPanelBar2.DataFieldID =

 

 

 

"Menu_Item_ID"  

 

    RadPanelBar2.DataFieldParentID =

 

 

 

"Parent_ID" 
    RadPanelBar2.DataTextField = "Name"  

 

    RadPanelBar2.DataNavigateUrlField =

 

 

 

"Page_URL"  

 

    RadPanelBar2.DataBind()

 

 

 

 

 

 

 

 

 

End Sub

2) Here's the ItemDataBound code - just copy and paste into Visual Studio, as it's a mess to read unformatted below:

 

Private

 

 

 

 

 

Sub RadPanelBar2_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadPanelBarEventArgs) Handles RadPanelBar2.ItemDataBound

 

 

 

 

 

 


'Additional Panel Information added

 

 

 

 

 

 

Dim lVirRootDir As String = Request.ApplicationPath.ToLower

 

 

 

 

 

 

Dim lMenuItem As DataRowView = CType(e.Item.DataItem, DataRowView)

 

e.Item.ImageUrl = lMenuItem(

 

"image_url")

 

 

e.Item.ToolTip = lMenuItem(

 

"tooltip")

 

 

e.Item.PostBack =

 

 

 

 

False

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If e.Item.Level > 0 Then

 

    e.Item.Height = Unit.Pixel(30)

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

pnlWelcome.Visible =

 

 

 

 

False

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Select Current Item and Expand Parent Menu Item Below

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If LCase(Request.FilePath) = LCase(lVirRootDir) & "/home.aspx" And Me.IsPostBack = False Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Home menu item selected (Expand the 'My Surveys' menu item)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If e.Item.Text = "Home" Then

 

 

 

 

 

 

 

 

 

e.Item.Selected =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ElseIf e.Item.Text = "My Surveys" Then

 

 

 

 

 

 

 

 

 

e.Item.Expanded =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

pnlWelcome.Visible =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ElseIf LCase(Request.FilePath) = LCase(lVirRootDir) & "/profile.aspx" And Me.IsPostBack = False Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'My Profile menu item selected (Expand the 'My Surveys' menu item)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If e.Item.Text = "My Profile" Then

 

 

 

 

 

 

 

 

 

e.Item.Selected =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ElseIf e.Item.Text = "My Surveys" Then

 

 

 

 

 

 

 

 

 

e.Item.Expanded =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Else

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'All Other Pages

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'--------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If CBool(ViewState("MenuURLDetected")) = False Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'=================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Refresh the last menu item selected and expanded

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'=================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If Session("MenuItemSelectedURL") IsNot Nothing Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If CStr(Session("MenuItemSelectedURL")) = LCase(e.Item.NavigateUrl) Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'e.Item.Selected = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If e.Item.Level = 0 Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'If a root lvl object, expand current panel

 

 

 

 

 

 

 

 

 

e.Item.Selected =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

e.Item.Expanded =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Else

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Expand parent Panel Item

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'e.Item.CssClass = "RadPanelbar_SelectedChildItem"

 

 

 

 

 

 

 

 

 

e.Item.BackColor = Drawing.Color.LightGray

 

 

 

 

 

DirectCast(e.Item.Owner, Telerik.Web.UI.RadPanelItem).Selected = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DirectCast(e.Item.Owner, Telerik.Web.UI.RadPanelItem).Expanded = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Else

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'=================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Mark the current menu item as selected and the parent as expanded

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'=================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Dim lURL As String = Request.FilePath.ToLower.Replace(lVirRootDir & "/", "")

 

 

 

 

 

 

If lURL = e.Item.NavigateUrl Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'e.Item.Selected = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If e.Item.Level = 0 Then

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'If a root lvl object, expand current panel

 

 

 

 

 

 

 

 

 

e.Item.Selected =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

e.Item.Expanded =

 

 

 

 

True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Else

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Expand parent Panel Item

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'e.Item.CssClass = "RadPanelbar_SelectedChildItem"

 

 

 

 

 

 

 

 

 

e.Item.BackColor = Drawing.Color.LightGray

 

 

 

 

 

DirectCast(e.Item.Owner, Telerik.Web.UI.RadPanelItem).Selected = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DirectCast(e.Item.Owner, Telerik.Web.UI.RadPanelItem).Expanded = True

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

Session(

 

 

 

 

"MenuItemSelectedURL") = LCase(lURL) 'Store the current menu item's URL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End Sub

 

 

 

 

 

 

 

 

 

0
Atanas Korchev
Telerik team
answered on 24 Feb 2009, 08:12 AM
Hi Chris,

We cannot run your code as it depends on external class libraries. I suggest you open a support ticket and send us a running page which demonstrates the problem.

Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chris
Top achievements
Rank 1
answered on 24 Feb 2009, 03:18 PM
Albert,

Sorry about that - I removed the project specific references from the code in the post above. The only thing that I would ask you do add is just some random datatable or dataset to bind to the RadPanelBar where the 'TODO Telerik comments are.

You can use any data you want to bind to the RadPanelbar, the point of this test code is not WHAT'S bound but HOW I handle the click events. So how I have it setup in html and how I handle things in the ItemDataBound for the RadPanelbar. This should reproduce what I'm seeing. Again, this didn't cause the client-side deselect in the original panel bar (so you can use this same kind of code but substitute the regular RadPanelbar and you want see the deselect affect) but it does in the ajax version.

Thanks,
Chris
0
Atanas Korchev
Telerik team
answered on 25 Feb 2009, 10:04 AM
Hi Chris,

Unfortunately I still couldn't implement your approach. Please excuse me for this.

I have used a slightly different approach demonstrated in our online example. Could you please try this approach instead? You should run the code in Page_Load after binding your panelbar:

  RadPanelBar1.DataBind()
  Dim clickedItem As RadPanelItem =    RadPanelBar1.FindItemByUrl(Request.Url.PathAndQuery)

            If Not (clickedItem Is Nothing) Then
                clickedItem.ExpandParentItems()
                ShowPath(clickedItem)
            End If


Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
PanelBar
Asked by
Chris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or