MVC Razor adding features to controls in Ext.onReady function

  1. #1

    MVC Razor adding features to controls in Ext.onReady function

    Hi!
    I created a simple view and a button on this view. I want to set listeners or other features in Ext.onReady function.
    but it does not works. here is my sample:
    @using Ext.Net;
    @using Ext.Net.MVC;
    @{
        Layout = null;
        var X = Html.X();
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Test</title>
    </head>
    <body>
        @(X.ResourceManager())
    
    
        <div> 
    @(X.Button().ID("Button1").Text("Button 1")
    
                )
        </div>
    </body>
    </html>
    <script type="text/javascript">
        Ext.onReady(function () {
    
            App.Button1.directEvents = { click: { fn: function (item, e) { Ext.net.directRequest({ cleanRequest: true, url: "/Stocks/HandleChanges", extraParams: { "data": '111' }, control: this }); } } }
    
        });
    
    
    </script>

    Thank you if you reply me faster
    Last edited by Daniil; Nov 10, 2014 at 11:45 AM. Reason: Please use [CODE] tags
  2. #2
    Hi @javadzarrin,

    Your Ext.onReady() handler is executed when the Button is created already. Setting a Button's directEvents after creating is not going to work.

    You can use a Button's PreInit.
    @(X.Button()
        .Text("Button 1")
        .PreInit(new JFunction
        {
            Handler = "this.directEvents = { click: { fn: function (item, e) { Ext.net.directRequest({ cleanRequest: true, url: '/Stocks/HandleChanges', extraParams: { data: '111' }, control: this }); } } }"
        })
    )
    A PreInit is executed before creating of a component.

    If you need to add DirectEvents on the fly after creating of a component, then it is not support. In this case please use regular listeners plus DirectMethods.

Similar Threads

  1. Razor: Custom Controls: 2 Controls as 1
    By bright in forum 2.x Help
    Replies: 0
    Last Post: Nov 09, 2013, 11:42 AM
  2. [CLOSED] Adding custom grid features
    By jchau in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 24, 2012, 4:58 PM
  3. Replies: 8
    Last Post: Jan 27, 2011, 9:33 PM
  4. Custom function in User Controls
    By pearl in forum 1.x Help
    Replies: 2
    Last Post: Apr 08, 2009, 12:56 AM
  5. Replies: 7
    Last Post: Nov 11, 2008, 3:59 AM

Tags for this Thread

Posting Permissions