[CLOSED] Reload a control to its default/original display state

  1. #1

    [CLOSED] Reload a control to its default/original display state

    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!
    Last edited by Daniil; Apr 25, 2012 at 2:35 PM. Reason: [CLOSED]
  2. #2
    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
  3. #3
    How about client-side?
  4. #4
    Well, here it is.

    Quote Originally Posted by Daniil View Post
    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
  5. #5
    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...
  6. #6
    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>
  7. #7
    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.
  8. #8
    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.

Similar Threads

  1. Can I save and after that Reload the filters state in Ext.NET Grid view
    By Nhím Hổ Báo in forum 1.x Help
    Replies: 14
    Last Post: Mar 26, 2015, 10:22 AM
  2. [CLOSED] How to reload tab (with user control)
    By macap in forum 1.x Legacy Premium Help
    Replies: 23
    Last Post: Nov 10, 2010, 10:49 AM
  3. Replies: 0
    Last Post: Aug 26, 2010, 2:58 PM
  4. Replies: 2
    Last Post: Apr 15, 2010, 5:33 AM
  5. Replies: 1
    Last Post: Jun 04, 2008, 10:28 PM

Posting Permissions