DirectMethod cant Register my Array

  1. #1

    DirectMethod cant Register my Array

    Hello. I have a DirectMethod, it creates an Array from database and register for JavaScript. If directMethod running in page_load, can register my Array. But direct method can register just in Page_Load. Why? Can u help me??
    Last edited by geoffrey.mcgill; Nov 08, 2012 at 2:45 AM.
  2. #2
  3. #3
    Hi,


    Please post a simplified code sample demonstration how to reproduce the scenario in question.


    Code that is not directly related to the problem should be removed from your sample. We should be able to copy/paste your sample into our local test project without having make modifications to avoid throwing Exceptions.


    Please review the following Forum Guidelines:


    http://forums.ext.net/showthread.php...ing-New-Topics


    http://forums.ext.net/showthread.php...ation-Required
    Geoffrey McGill
    Founder
  4. #4
    I have a DirectMethod like this. It create a dynamic Array from database. And register array with ClientScript.RegisterArrayDeclaration for using in Javascript. If this directMethod running in page_load., can register my Array.

    [DirectMethod]
            public void getCoordinates(int devId)
            {
                string latArrayStr=""; 
                string lngArrayStr="";
    
                ArrayList coordinates = new ArrayList();
    
                coordinates.AddRange((from c in context.Logs
                                           where c.devId == devId && c.LogId >= 100
                                           select new coordinates
                                           {                                         
                                               Lat = c.Latitude,
                                               Lng = c.Longitude
                                           }).ToList());
    
                for (int i = 0; i < coordinates.Count; i++)
                {
                    latArrayStr = latArrayStr + "\"" + ((MyProject.Coordinates)(coordinates[i])).Lat.ToString() + "\"";
                    lngArrayStr = lngArrayStr + "\"" + ((MyProject.Coordinates)(coordinates[i])).Lng.ToString() + "\"";
    
                    if (i != coordinates.Count - 1) 
                    {
                        latArrayStr = latArrayStr + ",";
                        lngArrayStr = lngArrayStr + ","; 
                    }
                }
                ClientScript.RegisterArrayDeclaration("latArray" + devId.ToString(), latArrayStr );
                ClientScript.RegisterArrayDeclaration("lngArray" + devId.ToString(), lngArrayStr);
    
            }

    Client Side(JS): Im calling DirectMethod like this. DirectMethod running correctly(created and registered my arrays) i can see with debugging, but i cant get my Arrays to JS.

    google.maps.event.addListener(marker, 'click', function () {
                                var dev = Store.getById(marker.title);
    
                                Ext.net.DirectMethods.getCoordinates(dev.data.devId, {
                                    success: function (result) {
                                        var a;
                                        var devicesCoordinates = [];
    
                                        var info = new google.maps.InfoWindow();
                                        info.setContent('<button type="button">button1</button>');
                                        info.open(map, marker);
                                        alert(dev.data.devId);                         
                                         latArray.push();
                                         lngArray.push();
                                    },
                                    failure: function (errorMsg) {
                                        Ext.Msg.alert('Hata', errorMsg);
                                    }
                                });
           });
    Last edited by Daniil; Nov 12, 2012 at 4:38 PM. Reason: Please use [CODE] tags
  5. #5
    Look at this code and say what part is not working:

    <!DOCTYPE html>
        
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
        <script>
            var sampleArray = [];
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <script runat="server">
                [DirectMethod]
                public void GetArray()
                {
                    X.AddScript("window.sampleArray = " + "[" + 1 + "]");
                }
            </script>
    
            <ext:Button runat="server" Text="Set array value" Icon="LaptopGo">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.GetArray();" />
                </Listeners>
            </ext:Button>
    
            <ext:Button runat="server" Text="Show array value" Icon="LaptopStart">
                <Listeners>
                    <Click Handler="Ext.Msg.alert('sampleArray value', window.sampleArray);" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Nov 12, 2012 at 8:59 PM.
  6. #6
    No, my example is different. I send a parameter to directMethod from JS. And directMethod creates Array. I want to get Array for using in JS. But i cant register my Array.
    Last edited by geoffrey.mcgill; Nov 12, 2012 at 8:54 PM.
  7. #7
    Unfortunately, you cannot register arrays with ClientScript. Ext.NET doesn't allow to other controls to write in response, because this can destroy generated JS and markup. However you can use X.Js :

    <script runat="server">
    	[DirectMethod]
    	public void GetArray()
    	{
    		X.Js.AddScript("window.sampleArray = " + "[" + 1 + "]");
    	}
    </script>
  8. #8
    Quote Originally Posted by kmlplt View Post
    No, my example is different. I send a parameter to directMethod from JS. And directMethod creates Array. I want to get Array for using in JS. But i cant register my Array.
    If you can put together a simplified .aspx code sample demonstrating the scenario, such as the sample provided by Baidaly above, we might be able to add additional support for your requirements.
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] How to register Trigger Icons?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 05, 2012, 12:43 PM
  2. [CLOSED] Namespace Does not register
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 22
    Last Post: Nov 07, 2011, 10:10 AM
  3. [CLOSED] register xtype
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Nov 03, 2010, 6:49 PM
  4. Replies: 8
    Last Post: May 25, 2010, 6:24 AM
  5. [CLOSED] Passing an array to a DirectMethod
    By macap in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 05, 2010, 10:28 AM

Tags for this Thread

Posting Permissions