9 Answers, 1 is accepted
TelerikStateService.asmx:
namespace MyProject { [WebService(Namespace = "http://tempuri.org/")] |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
[System.ComponentModel.ToolboxItem(false)] |
[System.Web.Script.Services.ScriptService] |
public class TelerikStateService : System.Web.Services.WebService |
{ |
[WebMethod(EnableSession=true)] |
public void TogglePane(string paneID, bool isCollapsed) |
{ |
Session[paneID + "_Collapsed"] = isCollapsed; |
} |
} } |
Master page markup:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptCombine="true"> |
<Services> |
<asp:ServiceReference Path="~/TelerikStateService.asmx" /> |
</Services> |
</telerik:RadScriptManager> |
<telerik:RadSplitter ID="RadSplitter1" runat="server"> |
<telerik:RadPane ID="MyPane" OnClientCollapsed="CollapsePane" OnClientExpanded="ExpandPane" runat="server"> |
... |
</telerik:RadPane> |
</telerik:RadSplitter> |
<script type="text/javascript"> function CollapsePane(sender, args) { |
MyProject.TelerikStateService.TogglePane(sender.get_id(), true); |
} |
function ExpandPane(sender, args) { |
MyProject.TelerikStateService.TogglePane(sender.get_id(), false); |
} </script> |
Master page Page_Load, call this method for each pane:
public void LoadPaneSettings(RadPane pane) |
{ |
bool paneCollapsed = (bool)(Session[pane.ClientID + "_Collapsed"] ?? false); |
pane.Collapsed = paneCollapsed; |
} |
Let me know if you can clean this up a bit for me ^.^
I am not quite sure how you implemented your cookies. In case you send me your code, I will review it and probably would find the cause for the duplication.
I have attached a simple test page that demonstrates one implementation of your scenario. I hope this would help you.
Sincerely yours,
Tsvetie
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.
I love the cookie approach, and you're correct that the above example works great for preserving the docked state,
but we are attempting to store the width as well. So, while there isn't a problem obtaining the width on the client side, there IS a problem setting the width on the client side. I am unaware of a client side method that sets the RadSlidingPane's width on the client side, so I'm attempting to set the width on the server side, and therein lies the problem.
Expanding upon the original code to store the docking info and the width:
var SplitterCookie = "SplitterCookie"; |
var SplitterCookieDelimiter = "*"; |
function PreserveState(sender, eventArgs) |
{ |
debugger; |
var zone = $find('<%= SlidingZone1.ClientID %>'); |
var expandedPaneID = zone.get_dockedPaneId(); |
expandedPaneID += SplitterCookieDelimiter + sender.get_width(); |
SetCookie('SplitterCookie', expandedPaneID); |
} |
function OnClientLoaded(object, args) |
{ |
var zone = object; |
var dockedPaneID = GetCookie('SplitterCookie'); |
if (dockedPaneID) |
{ |
debugger; |
var docked = dockedPaneID.substring(0, dockedPaneID.indexOf(SplitterCookieDelimiter)); |
if(docked) |
{ |
setTimeout(function(){ |
zone.dockPane(docked); |
}, 0); |
} |
} |
} |
private const String _SPLITTERCOOKIENAME = @"SplitterCookie"; |
private const char _SPLITTERCOOKIEDELIMITER = '*'; |
/// <summary> |
/// Gets the cookie used for storing the client persisted state of the Splitter |
/// </summary> |
private void GetSplitterPersistenceCookie() |
{ |
HttpCookie cookie = Request.Cookies[_SPLITTERCOOKIENAME]; |
if (cookie != null) |
{ |
string[] cookieValues = cookie.Value.Split(_SPLITTERCOOKIEDELIMITER); |
Nav.Width = new Unit(Double.Parse(cookieValues[1]), UnitType.Pixel); |
} |
} |
When we attempt to retrieve the cookie on page_load of the master page, we often get the correct cookie value. However, while going from page to page, we soon see a duplicate cookie, and so we end up retrieving an invalid value.
Any thoughts?
Adam.g
You can use the set_width client-side method of the RadSlidingPane to set the width of the sliding pane on the client. For example:
<telerik:RadSplitter ID="RadSplitter1" runat="server"> |
<telerik:RadPane ID="RadPane1" runat="server" Width="22px"> |
<telerik:RadSlidingZone ID="RadSlidingZone1" runat="server"> |
<telerik:RadSlidingPane ID="RadSlidingPane1" Width="150" runat="server" Title="Pane 1"> |
</telerik:RadSlidingPane> |
</telerik:RadSlidingZone> |
</telerik:RadPane> |
<telerik:RadSplitBar ID="RadSPlitBar1" runat="server" /> |
<telerik:RadPane ID="RadPane2" runat="server"> |
<button onclick="SetSlidingPaneWidth(300);return false;">Set 300 px as width</button> |
</telerik:RadPane> |
</telerik:RadSplitter> |
<script type="text/javascript"> |
function SetSlidingPaneWidth(newWidth) |
{ |
var slidingPane = $find('<%= RadSlidingPane1.ClientID %>'); |
slidingPane.set_width(newWidth); |
} |
</script> |
Make sure that you first set the new width for the sliding pane and then dock it.
All the best,
Tsvetie
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
I have taken this approach as well, and am finding the same problem that Adam had... How did / can you get around this?
When you say "gave up on checking cookies", what are you saying exactly?
Right now, I'm doing this:
function
OnClientLoaded(object, args) {
var
zone = object;
var
dockedPaneID = getCookie(
'dockedID'
);
alert(
"setting pane to "
+ dockedPaneID);
if
(dockedPaneID) {
setTimeout(
function
() {
zone.dockPane(dockedPaneID);
}, 0);
}
}
are you saying that you are not getting the cookie (line above the alert)?
Thanks in advance Adam!
For now, this approach isn't going to work, but I have changed the idea that Telerik gave and it seems to be working. Basically, I just set an expiration on the cookie for 30 minutes. Even though I have waited longer than 30 minutes between postbacks, the solution seems to still be working
function
setCookie(name, value, minutes) {
if
(seconds) {
var
date =
new
Date();
date.setTime(date.getTime() + (minutes * 60 * 1000));
var
expires =
"; expires="
+ date.toGMTString();
}
else
var
expires =
""
;
document.cookie = name +
"="
+ value + expires +
"; path=/"
;
}
function
PreserveState() {
var
zone = $find(
'<%= mainSlidingZone.ClientID %>'
);
var
expandedPaneID = zone.get_dockedPaneId();
setCookie(
'dockedID'
, expandedPaneID, 30);
}
Thanks for your help Adam... If we find that this isn't going to work, I will take your advice and use Max's approach.