[CLOSED] Components created in a Direct Response do not always generate correct script

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] Components created in a Direct Response do not always generate correct script

    Hi,

    Consider this markup:

    <%@ Page Language="C#" %>
    <!DOCTYPE html>
    <html>
        <head>
            <title>Example</title>
        </head>
        <body>
            <ext:ResourceManager runat="server" Theme="Gray" />
    
            <ext:Button runat="server" Text="Get Server Time">
                <DirectEvents>
                    <Click 
                        Url="WebServices/ServerTimeService.asmx/GetServerTimeWindow" 
                        Type="Load" 
                        Method="POST" 
                        CleanRequest="true" />
                </DirectEvents>
            </ext:Button>
        </body>
    </html>
    This is the service:

    using System;
    using System.Web.Services;
    using Ext.Net;
    
    namespace Ext.Net2.Tests.Direct.WebServices
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class ServerTimeService : WebService
        {
            [WebMethod]
            public DirectResponse GetServerTimeWindow()
            {
                var window = new Window("Server time", Icon.Time)
                {
                    ID = "MyWindow",
                    Html = DateTime.Now.ToString(),
                    Hidden = true
                };
    
                // some condition makes us show it now
                window.Show();
    
                return new DirectResponse(window.ToScript());
            }
        }
    }
    This is the script portion of the output slightly pretty printed:
    Ext.net.ResourceMgr.destroyCmp("App.MyWindow");
    Ext.create("Ext.window.Window",{
      id:"MyWindow",
      height:100,
      html:"12/05/2012 00:01:57",
      renderTo:Ext.getBody(),
      width:200,
      title:"Server time",
      iconCls:"#Time"});
    MyWindow.show();
    The problem is the very last line.

    Because I have set the window to be hidden, it doesn't actually show. The reason is there is an error in the script that is generated. Although I have simulated a scenario where the window should be shown using window.Show();, the output creates MyWindow.show() instead of App.MyWindow.show().

    I see on the first line you are able to figure out the namespace is App and destroy the component first, so hopefully this means this last line can be fixed too?

    But this then got me wondering: as I understand it, the "App" namespace can be customzied in web.config and/or the resource manager and "App" is only the default. So
    • How will you know what namespace to use?
    • If the namespace for the client objects is defined on the ResourceManager on the originating ASPX page you would not know which one to use?


    For example, if I do this:

    <ext:ResourceManager runat="server" Theme="Gray" Namespace="CompanyX" />
    The script that is returned during the DirectEvent is still
    Ext.net.ResourceMgr.destroyCmp("App.MyWindow");
    Maybe a solution to this second part is to always have a known alias when you initialize your pages? For example, with the above CompanyX example, this is currently what your code produces:
    Ext.net.ResourceMgr.init({id:"ctl00",theme:"gray",ns:["CompanyX"]});
    But maybe it can do something like this:

    Ext.net.ResourceMgr.init({id:"ctl00",theme:"gray",ns:["CompanyX"]});
    Ext.net.App = CompanyX;
    I use Ext.net.App instead of App as it might be a bit "safer" (someone else doesn't accidentally create App, for example, and override all your stuff).

    Maybe this way you can then always safely use Ext.net.App.MyWindow in the above examples?
    Last edited by Daniil; May 14, 2012 at 10:48 AM. Reason: [CLOSED]

Similar Threads

  1. Replies: 0
    Last Post: Aug 05, 2012, 10:46 AM
  2. [CLOSED] Can I use Response object in a direct method call?
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 12, 2012, 11:50 AM
  3. [CLOSED] return html server response instead of just long extjs script!
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 17, 2011, 8:38 AM
  4. Replies: 0
    Last Post: Aug 05, 2009, 9:48 AM
  5. [CLOSED] CheckboxSelection model and script in every response
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 04, 2009, 11:09 AM

Tags for this Thread

Posting Permissions