PDA

View Full Version : [CLOSED] Reload a control to its default/original display state



MacGarnicle
Apr 24, 2012, 8:18 PM
Let?s say I have a button. When I click it a window opens. I then resize and reposition this window. Then I close it. The next time I click the button and the window opens, I want it to be in its default state ? The state it was in before I resized the window and moved it around.

Essentially, I want to be able to reload the control, either client side, or server side without all the changes I just made to it.

I can also say that about a grid for example. I show/hide columns, and I may want a button that sets everything back to how it was originally, without reloading the entire page.

Any ideas how I can achieve this both client-side and server-side?

Thanks!

Daniil
Apr 24, 2012, 8:58 PM
Hi,

I would try with re-rendering a control from server side first.

You will need to just call the Render method of the control.

Window1.Render();

Then a control will be fully re-rendered with the initial state.

To ensure the state save/restore mechanism won't affect the previous changes of the control state, you might need to set up

Stateful="false"
for that control.

Another approach can be saving a control state client side, then restoring it client side using client side JavaScript API of the control.

Here is some related discussion.
http://forums.ext.net/showthread.php?14637

MacGarnicle
Apr 24, 2012, 9:09 PM
How about client-side?

Daniil
Apr 25, 2012, 7:25 AM
Well, here it is.



Another approach can be saving a control state client side, then restoring it client side using client side JavaScript API of the control.

Here is some related discussion.
http://forums.ext.net/showthread.php?14637

MacGarnicle
Apr 25, 2012, 1:44 PM
Thank you very much for your responses.

For the grid example, I went as far as using getState when the page is loaded. I would then use "Ext.override" so I can modify the behaviour of applyState to whatever I want. Then when I needed a reset, I would call applyState. For some reason I couldn't get that working for the Window...

Daniil
Apr 25, 2012, 2:26 PM
Good point.

Well, the Window applyState can't restore a state of already rendered Window.

But it can be easily done manually.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!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>Ext.NET v2 Example</title>

<script type="text/javascript">
var restore = function (win) {
var state = win.initialState;

if (state.maximized) { //didn't test
win.maximize();
return;
}

win.setSize(state.size);
win.setPosition(state.pos);
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Window ID="Window1" runat="server">
<Listeners>
<AfterRender
Handler="this.initialState = this.getState();"
Delay="1" />
</Listeners>
</ext:Window>

<ext:Button runat="server" Text="Restore">
<Listeners>
<Click Handler="restore(App.Window1);" />
</Listeners>
</ext:Button>
</form>
</body>
</html>

MacGarnicle
Apr 25, 2012, 2:31 PM
Yes - that is perfect - it's what I will end up using. Too bad Ext.js didn't include a function like restoreToInitialState for all it's controls. It's what I was hoping to find :)

Thanks.

Daniil
Apr 25, 2012, 2:35 PM
Well, yes, it would be a helpful feature.

But, there is so many-many various config options and, finally, I think it would be a very big deal to implement such feature.

Re-rendering is the answer :) Or manual restoring of required things only. Or using already implemented functionality like as it is in the case with GridPanel.