Simon
Simon

Reputation: 2830

How to stop RadPanelBar navigating to a hash

I have a RadPanelBar as such...

<telerik:RadPanelBar 
    ID="ResourcesSubMenuRadPanelBar1"
    Width="195px" 
    OnItemClick="RadPanelItemClick"
    ExpandMode="MultipleExpandedItems"    
    OnClientItemClicked="RadPanelClientItemClicked"       
    OnClientLoad="RadPanelBarClientLoad"     
    runat="server" 
    AppendDataBoundItems="true" 
    EnableEmbeddedSkins="false" 
    OnClientItemCollapse="RadPanelClientItemClicked" 
    OnClientItemExpand="RadPanelClientItemClicked">    
</telerik:RadPanelBar>

This all works as expected, except for one little thing. In the code behind, I explicitly set the NavigateUrl property to string.Empty but when an item is clicked, it adds a hash to the url. Obviously, this is because the href attribute has been set to "#" when the control renders the HTML.

I know that I can simply return false from the OnClientItemClicked event, but that will stop the ItemClick event from being fired on the server.

As I say, there is no real error with this code it's just bugging me (and, more importantly, the end users) that there is a # added to the URL.

Does anyone know how to stop this happening?

Upvotes: 0

Views: 1469

Answers (2)

tuespetre
tuespetre

Reputation: 1887

Compatible in just about every browser, IE9 and up:

Javascript (no jQuery):

stripTelerikHashtag = function () {
    [].forEach.call(
        document.querySelectorAll(".rpLink"),
        function (a) { a.removeAttribute("href") }
    );
};

Javascript (with jQuery):

stripTelerikHashtag = function () { $(".rpLink").removeAttr("href"); };

In your ASP, set OnClientLoad on the RadPanelBar to stripTelerikHashtag.

Upvotes: 0

Krishnan
Krishnan

Reputation: 1504

Try this in your OnClientItemClicking event: eventArgs.set_cancel(true);

Ref: http://www.telerik.com/help/aspnet-ajax/panelbar-onclientitemclicking.html


And, if in case you want the post back to happen, I suppose there is a item.PostBack property (server-side). Set it to true. It should post you back - if the NavigateUrl is empty (or #).

Upvotes: 1

Related Questions