[CLOSED] RegisterOnReadyScript in MVC partial view

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] RegisterOnReadyScript in MVC partial view

    Hi, I'm trying to register an on-ready script in my MVC partial view but it won't fire. When I register an on-ready script from a view page, it works fine.

    This is how I register the script from within the partial view:

    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            ResourceManagerProxy.ResourceManager.RegisterOnReadyScript("alert('child document ready');");
        }
    </script>
    <ext:ResourceManagerProxy ID="ResourceManagerProxy" runat="server" />
    Here's how I render the partial view from my main view page:
        <%= Html.RenderExtPartial("ViewUserControl1") %>
    The same technique is used in the Ext.Net.MVC demo but in that case it is used from within an auto loading window, not a partial view that is loaded using Html.RenderExtPartial.

    I have attached a sample project. It is supposed to show an alert that states 'child document ready' but that doesn't happen.
    Attached Files
    Last edited by Daniil; Jan 20, 2011 at 9:49 AM. Reason: [CLOSED]
  2. #2
    Hi,

    OnReady event is fired when DOM tree is ready (built) in the browser. If you use partial view it is mean that page is loaded already in the browser and OnReady event is fired already.

    Therefore RegisterOnReadyScript has no sense in the partial view and doesn't work. I can suggest to use AfterRender event of any Ext.Net widget inside partial view
  3. #3
    Thanks, that is a clear answer allright.

    I'm having trouble though, finding a good spot for the AfterRendered handler because my partial view (unlike the provided sample) consists of a BorderLayout with some panels inside. BorderLayout does not support listeners so I have to put the listener on a panel. But in that case the listener is executed too early and I guess rendering order is not guaranteed so things may get worse in that respect.
  4. #4
    Hi,

    Well, what about the following structure
    <ext:FitLayout ...>
         <Items>
               <ext:Container ... Layout="Border">
                      <Items>
                             ...
                      </Items>
                      <Listeners>
                               <AfterLayout Fn="myFn" Single="True"/>
                      </Listeners>
               </ext:Container>
         </Items>
    </ext:FitLayout>
    I mean to create extra Container and use AfterLayout event which will be fired after rendering and relayouting all inner items
  5. #5
    Thanks. I've tried it but somehow the listener is still executed too early because I try to execute a function that is declared within the partial view (I've put the script in the Contents of the inner panel) and the browser says it is not declared (yet). If I put a handler="setTimeout..." on the listener, it works correctly.
  6. #6
    Hi,

    Instead of setTimeout() you could use the Delay property.

    Example
    <AfterLayout Fn="myFn" Single="True" Delay="100" />
  7. #7
    Hi, thanks for the hint -- I'll keep that in mind the next time I try to use a timeout. In this case, I use the timeout only as a temporary solution. A good solution to the problem should not use timing at all. I mean, what delay would be proper? The shorter, the bigger the chance of firing too early and the longer, the bigger the chance of firing later than optimal (and the bigger the sluginess).
  8. #8
    Hi,

    You are right, delaying is not the best.

    We're trying to find a better solution.
    Last edited by Daniil; Nov 29, 2010 at 2:11 PM.
  9. #9
    Hi,

    I guess that the issue can be related with content element moving. Content area is rendered as hidden div, after panel rendering the element is moved by the panel inside own body (moving assumes removing from old position in the DOM tree and insert to another).

    I need to create test sample and play with it to find good solution. I will notify about the result
  10. #10
    Thanks Vladimir, I hope you can find an elegant solution.
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] Loading Partial View under a formpanel
    By Daly_AF in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 25, 2012, 2:26 PM
  2. [CLOSED] Problems with BaseParams in Partial View
    By GLD in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 13, 2012, 2:50 PM
  3. [CLOSED] Partial View Error
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 10, 2012, 10:32 AM
  4. [CLOSED] Partial View & FormPanel Submit
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 14, 2011, 12:01 PM
  5. [CLOSED] MVC- How to display a Partial View from a window
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 08, 2011, 11:32 AM

Tags for this Thread

Posting Permissions