Hi all,
I am attempting to maintain the position of a RadSplitBar on postback. I am able to maintain -a- position, but am having trouble progressing it further than that.
My understanding is this:
When the RadSplitBar is moved it's related RadPane's are resized. Therefore, I would like to capture the RadPane's resize event. Unfortunately, there is no server side handling of this by default. So, I must capture OnClientResized events. This puts me off into client-side javascripting, though...and writing to Session isn't a simplistic procedure.
Is there a simple way to run some server-side code after capturing the OnClientResized event?
Ideally, it would be something like this:
Where SaveState is server-side code I have written to record the pane's height and width to Session. Should I be looking into AJAX for this functionality?
EDIT: (Disclaimer: This won't be very pretty.) I managed to do this, but it's quite the workaround. If you guys have any better ideas it would be appreciated.
Here's the gist of it:
This code won't compile if you just copy/paste it, I'm using a lot of other helper functions, but if you're stuck with this problem this would be a good place to start. From here you'll need to look up the demo example on persisting state in session.
I am attempting to maintain the position of a RadSplitBar on postback. I am able to maintain -a- position, but am having trouble progressing it further than that.
My understanding is this:
When the RadSplitBar is moved it's related RadPane's are resized. Therefore, I would like to capture the RadPane's resize event. Unfortunately, there is no server side handling of this by default. So, I must capture OnClientResized events. This puts me off into client-side javascripting, though...and writing to Session isn't a simplistic procedure.
Is there a simple way to run some server-side code after capturing the OnClientResized event?
Ideally, it would be something like this:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function OnClientResized(pane, arg) {
pane.SaveState();
}
</
script
>
</
telerik:RadCodeBlock
>
Where SaveState is server-side code I have written to record the pane's height and width to Session. Should I be looking into AJAX for this functionality?
EDIT: (Disclaimer: This won't be very pretty.) I managed to do this, but it's quite the workaround. If you guys have any better ideas it would be appreciated.
Here's the gist of it:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function OnClientResized(pane, args) {
var context = new Object();
var paneIDandHeight = pane.get_id() + ',' + pane.get_height();
//Context is just thrown away.
CallSetDimensions(paneIDandHeight, context);
}
function CallbackOnSucceeded(result, context) {
//Logging
}
function CallbackOnFailed(result, context) {
//Logging
}
</
script
>
</
telerik:RadCodeBlock
>
public
partial
class
_Default : System.Web.UI.Page, ICallbackEventHandler
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
RegisterCallBackReference();
}
private
void
RegisterCallBackReference()
{
//Target: The name of a server Control that handles the client callback.
//Argument: An argument passed from the client script to the server.
//clientCallback: The name of the client event handler that receives the result of success.
//context: Client script that is evaluated on the client prior to initating the callback.
//clientErrorCallback: The name of the client event handler that handles an error.
//useAsync: True/False asynchronous postback.
String callBack = Page.ClientScript.GetCallbackEventReference(
this
,
"arg"
,
"CallbackOnSucceeded"
,
"context"
,
"CallbackOnFailed"
,
true
);
String clientFunction =
"function CallSetDimensions(arg, context){ "
+ callBack +
"; }"
;
Page.ClientScript.RegisterClientScriptBlock(
this
.GetType(),
"Call To Server"
, clientFunction,
true
);
}
#region ICallbackEventHandler Members
String returnValue;
string
ICallbackEventHandler.GetCallbackResult()
{
return
returnValue;
}
void
ICallbackEventHandler.RaiseCallbackEvent(
string
eventArgument)
{
bool
result = SetDimensions(eventArgument);
if
(result)
{
returnValue =
"Success."
;
}
else
{
returnValue =
"Failure."
;
}
}
#endregion
private
bool
SetDimensions(
string
args)
{
bool
saveSuccessful =
false
;
string
[] paneIDandHeight = args.Split(
','
);
string
paneID = paneIDandHeight[0];
string
paneHeight = paneIDandHeight[1];
RadPane pane = Utilities.FindControlRecursive(Page, paneID)
as
RadPane;
int
height = 0;
int
.TryParse(paneHeight,
out
height);
if
(!
object
.Equals(pane,
null
))
{
saveSuccessful =
true
;
RadPaneSetting paneSetting = RadPaneSetting.GetSettings(pane);
pane.Height =
new
Unit(height, UnitType.Pixel);
SavePane(pane);
}
return
saveSuccessful;
}
}
This code won't compile if you just copy/paste it, I'm using a lot of other helper functions, but if you're stuck with this problem this would be a good place to start. From here you'll need to look up the demo example on persisting state in session.