[CLOSED] ext:Button: Adding listener to a click event

  1. #1

    [CLOSED] ext:Button: Adding listener to a click event


    I'm creating my ext:window as javascript: It is working.
    But, I wish pass the buttons of window as parameter of the function;
    I'm creating a function below to create a button. But my problem is: I want set the javascript that be executed when the button is clicked.

    In vb.Net, i do this:
    function createButton(text as string, fn as string)
         dim btn = New Ext.Net.Button
         btn.Id = "btnOk"
         btn.Text = text
        btn.Listeners.Click.Handler = fn
        return btn
    end function
    How I do it in Javascript?

            function createButton(text, fn) {
                var btn;
                btn = Ext.create("Ext.button.Button", {
                    id: "btn" + text,
                    text: text
                btn.on("click", "function () {" + fn + "}");
                return btn;
    Last edited by geoffrey.mcgill; Apr 13, 2012 at 12:09 AM. Reason: [CLOSED]
  2. #2

    The best way to figure this out is to configure in code-behind, then view the Page in a browser, then View > Source to see the client-side configuration script generated.

    You can then take that script and pull out the piece you required.

    Hope this helps.
    Geoffrey McGill
    Founder & CEO
  3. #3
    Hi Geoffrey... thanks for your suggestion...

    Daniil gave me this tip before, and I have used enough.

    But, in this case, The function in listener click not static... I wish pass this function as parameter, because, depending the window where I am, I want a different action on the OK button click of window. My window is created in Javascript code too.

    My problem is transform a string with javascript function passed as parameter in a function associated to click listener.

    In codebehind, it's easy:

    btn.Listeners.Click.Handler = fn
    Where 'fn' is a string with javascript function.

    But, I don't know how I do it in Javascript.

    I'm trying this way (in Javascript), but, don't works:

    btn.on("click", "function () {" + fn + "}");
  4. #4
    In JavaScript I would suggest to pass a function instance as a parameter.

    Then it will look this way:
    function createButton (text, fnParam) {
        var btn;
        btn = Ext.create("Ext.button.Button", {
            id    : "btn" + text,
            text  : text,
            listeners : {
                click : {
                    fn : fnParam
        return btn;
  5. #5
    In your suggestion, the 'fnParam' is a javascript function or a string contains java script function code?
  6. #6
    A JavaScript function.

    It's my suggestion - pass a JavaScript function as a parameter.
  7. #7

    Thanks a lot for your help!

    I pass the javascript function as parameter and works very fine... I will try now use this in my real source code...

    If you want, you can close this thread... If I have new difficults, I create a new thread.

    Thanks a lot, again

Similar Threads

  1. Replies: 2
    Last Post: Apr 09, 2012, 2:13 PM
  2. [CLOSED] Adding a listener to BeforeDestroy event on TabPanel
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 22, 2012, 12:49 PM
  3. Click Listener to Button from Code-Behind
    By Alexx in forum 1.x Help
    Replies: 7
    Last Post: Jul 26, 2011, 11:26 AM
  4. Replies: 10
    Last Post: Aug 18, 2010, 2:22 AM
  5. [CLOSED] Button Click Listener bug
    By methode in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Apr 26, 2010, 11:40 AM

Posting Permissions