[CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

  1. #1

    [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    I have the following code inside OnPreRenderComplete method of a Page:

    resourceManager.RegisterClientScriptInclude(resour ce.physicalPath, resource.clientPath + "?v=" + this.cacheBuster);


    The Resource gets included properly on a GET request. However, in a DirectMethod call, the resources do not get registered on the page. What should I call to get the Script Includes registered in a DirectMethod call?
  2. #2

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    Hi,

    Well, there is 'Ext.net.ResourceMgr' javascript class which can loads resources dynamically
    JS load
     X.Js.Call("Ext.net.ResourceMgr.load", new { url = "myresource.js", callback="jsFunctionName" });
    CSS load
    X.Js.Call("Ext.net.ResourceMgr.load", new { url = 
    "mycss.css", mode="css",  callback = "jsFunctionName" });
  3. #3

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    Thanks for the reply vlad. I have another problem: methods like RegisterClientInitScript, AddBeforeClientInitScript etc. on ResourceManager also do not produce anything in the DirectMethod.

    The problem is I need to ensure that some part of the js that I need to register dynamically in DiectMethod always executes before the other script generated by Ext.net framework.


    How can I register a script block to execute before any other scrip generated by Ext.net framework in a DirectMethod??
  4. #4

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    Hi,

    Use AddScript of any Ext.Net control (it can be ResourceManager also)
    AddScript method always honor script calling sequence on global level

    If I misunderstood you still then please provide test sample which demonstrate your scenario
  5. #5

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    vlad, consider the following output of a DirectMethod:

    {script:"Ext.net.append(Ext.net.getEl(Ext.get(\"form1\")),[\"<div id=\\\"id49229302f48642a688922e19af39432c_Container\\\">\",\"<div id=\\\"id49229302f48642a688922e19af39432c_Content\\\" class=\\\"x-hidden\\\"><div id=\\\"ctlReservation_hRes_Container\\\" style=\\\"display:inline;\\\">\",\"
    \",..........................

    Now, if I call Ext.Net.Control.AddScript, it gets added when it was called, i.e. somewhere in between the output of the DirectMethod (as you said AddScript honors calling sequence on global level).


    I want my script to be at the beginning of the putput of the DirectMethod, i.e. before Ext.net.append in the above output.
  6. #6

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    e.g if I call ResourceManager.AddBeforeClientInitScript in a normal GET request, the script gets added before any other script generated by Ext.net framework.

    I need something similar for a DirectMethod.
  7. #7

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    Hi,

    Please see
    <%@ 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">
    
    <script runat="server">
        protected void RenderClick(object sender, EventArgs e)
        {
            ResourceManager1.AddScript("alert('I am first');");
    
            Window w = new Window { ID = "W1", Title="Window" };
            w.ContentControls.Add(new LiteralControl("I am window"));
            w.Render();
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:Button runat="server" Text="Render window">
                <DirectEvents>
                    <Click OnEvent="RenderClick" />
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Response
    {script:"alert('I am first');Ext.net.append(Ext.net.getEl(Ext.getBody()),["<div id=\\"W1_Content\\" class=\\"x-hidden\\">I am window
    "].join(''));Ext.net.ResourceMgr.destroyCmp("W1");new Ext.Window({id:"W1",renderTo:Ext.getBody(),height:100,width:200,title:"Window",contentEl:"W1_Content",hidden:false});"}
  8. #8

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    vlad, I really appreciate you taking time out to answer my queries.

    My situation is not so simple. I am rendering a UserControl inside the DirectMethod. The Usercontrol in turn registers nested UserControls to itself. Those nested UserControls need to check a condition and if true, need to make sure that a particular call to a javascript method executes before any other code generated for the DirectMethod.


    Off-course there can be workaround (using Interfaces). But I was wondering if there was a more direct approach available. Why can't a call to:
    Ext.Net.X.ResourceManager.AddBeforeClientInitScrip t


    inside a DirectMethod add the script before other script generated for the DirectMethod response.
  9. #9

    RE: [CLOSED] [1.0] How to Register Client Script Includes in a DirectMethod

    Hi,

    AddBeforeClientInitScript add script before initialization script. But as you understood the initialization script is generated for none ajax request only. During ajax request only scripts from controls are used (AddScript method)


    Therefore, at this moment, you have to use your workaround. We will think about ability to add own scripts before all controls scripts during ajax event


    Ticket: http://extnet.lighthouseapp.com/proj...ng-directevent

Similar Threads

  1. [CLOSED] Client script against usercontrol element
    By jwf in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 03, 2011, 4:22 PM
  2. [CLOSED] Resize Region in ViewPort via client-script
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 24, 2011, 7:17 PM
  3. [CLOSED] [1.0] How to add client script in before OnReady?
    By bsnezw in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 14, 2010, 10:56 AM
  4. Ext.Msg.Alert from client script error
    By rthiney in forum 1.x Help
    Replies: 3
    Last Post: Jul 09, 2009, 3:51 PM
  5. Script includes in section
    By rcaunt in forum 1.x Help
    Replies: 0
    Last Post: Jun 03, 2009, 11:25 AM

Posting Permissions