[CLOSED] Scoping all the ext.net handlers...

  1. #1

    [CLOSED] Scoping all the ext.net handlers...

    Hi,

    Is there a way to "Scope" all ext.net handler functions to use the object you're send it to, without setting Scope everywhere?

    For example, if you have a object literal that contains business logic, you might have a method like:

    var busLogic = {
        counter: 1,
    
        handleButtonClick: function() {
            counter ++;
        }
    }
    If you made a button and set the click fn to busLogic.handleButtonClick, then this would fail because "this" will be set to the button. I want to avoid setting the scope param of the click handler...

                                    <Listeners>
                                        <Click Fn="busLogic .handleButtonClick" Scope="Dont want to" />
                                    </Listeners>
    Last edited by Daniil; Sep 21, 2012 at 11:01 AM. Reason: [CLOSED]
  2. #2
    Hi @PhilG,

    Unfortunately, there is no such setting.

    There are some possible solutions.

    1. Use explicitly "busLogic.counter". I would prefer this way.

    Example 1
    <%@ 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 Example</title>
    
        <script type="text/javascript">
            var busLogic = {
                counter: 1,
     
                handleButtonClick: function() {
                    alert(busLogic.counter++);
                }
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Button runat="server" Text="Click me">
            <Listeners>
                <Click Fn="busLogic.handleButtonClick" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    2. With Scope which you don't like. Please note that you will have to use "this.counter" instead of just "counter".

    Example 1
    <%@ 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 Example</title>
    
        <script type="text/javascript">
            var busLogic = {
                counter: 1,
     
                handleButtonClick: function() {
                    alert(this.counter++);
                }
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Button runat="server" Text="Click me">
            <Listeners>
                <Click Fn="busLogic.handleButtonClick" Scope="busLogic" />
            </Listeners>
        </ext:Button>
    </body>
    </html>

    3. Use Hanlder instead of Fn.

    Example 3
    <%@ 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 Example</title>
    
        <script type="text/javascript">
            var busLogic = {
                counter: 1,
     
                handleButtonClick: function() {
                        alert(this.counter++);
                    }
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Button runat="server" Text="Click me">
            <Listeners>
                <Click Handler="busLogic.handleButtonClick();" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Last edited by Daniil; Sep 20, 2012 at 7:29 PM.
  3. #3
    Thanks for the suggestions. I knew the first 2, but wasn't aware that using Handler would behave in that way - I like that solution - thanks!

    Matt

Similar Threads

  1. JSONP and Webservices versus Generic Handlers
    By plykkegaard in forum 1.x Help
    Replies: 3
    Last Post: Feb 21, 2012, 12:41 PM
  2. Replies: 8
    Last Post: Jan 04, 2012, 4:23 PM
  3. [CLOSED] [1.0] New ns scoping concept
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 02, 2010, 7:34 PM
  4. Replies: 2
    Last Post: Dec 01, 2010, 10:14 AM
  5. [CLOSED] [1.0] Notification handlers
    By state in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Oct 28, 2009, 8:49 AM

Posting Permissions