[CLOSED] Adding Custom Events

  1. #1

    [CLOSED] Adding Custom Events

    Hiya,

    I am wondering what the best way to add custom events to controls.

    An example is the "mousdown" and "mouseup" events on a button. I can do this by writing javascript code such as

    
    protected void Page_Load(object sender, EventArgs e)
    {
          string fn = "Ext.get('mybutton').on('mousedown',function(){alert('mousedown')});";
          this.ScriptManager1.RegisterOnReadyScript(fn);
            
    }
    What I was trying to use initially was manipulate the button control directly through code snippets (which I could not get to work) such as

    
    this.mybutton.AddEvents("mousedown");
    this.mybutton.AddListener("mousedown", fn);
    Firstly, is it possible to achieve the above through code on the server side, or through the Listener "Add" tag in the control itself?

    But my main question is, which way would you recommend we achieve the required results?

    thanks,
    Conor
  2. #2

    RE: [CLOSED] Adding Custom Events



    Hi Conor,

    I'm writting a sample for you, but I just have one quick question... I'm assuming "mybutton" is an <ext:Button> control? or is it an <asp:Button> control?
    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] Adding Custom Events


    You assume correctly :-)

    Sorry, I didnt think of mentioningthat. I also didnt know you could add ext listeners to asp:button controls...

    thanks.

  4. #4

    RE: [CLOSED] Adding Custom Events



    Hi Conor,

    Thanks for the clarification.

    But my main question is, which way would you recommend we achieve the required results?
    Well... you've got options. I added a new example to the explorer which demonstrates several techniques for adding a Listener to a Button. The example uses the "click" listener, but the same code would apply for any Listener you want to add.

    See https://examples1.ext.net/#/Listener.../Add_Listener/

    Hope this helps.
    Geoffrey McGill
    Founder
  5. #5

    RE: [CLOSED] Adding Custom Events



    I just noticed that you are adding the "mousedown" and "mouseup" which are not directly supported listeners on <ext:Button>.

    Give me a few minutes to come up with another example.
    Geoffrey McGill
    Founder
  6. #6

    RE: [CLOSED] Adding Custom Events

    I'm not a premium support member as yet, but I had a similar challenge I thought I'd share here since it's related to this post. I matched the code found in your examples explorer under Listeners Basic to add additional listeners that were not discovered when using Intellisense with the Listeners property.

    I found when I tried adding listeners to panels, labels and a few other coolite controls, I could not add mouseover or mouseout events as follows:
    
    
    
    var lbl = new Coolite.Ext.Web.lbl("Test");
    lbl.ID = String.Format( "ctlM00", Month, Day );
    pnl.BodyControls.Add( lbl );
    lbl.AddEvents( "'mouseover'" );    // note: i had to add apostrophies to get the client-side to compile
    lbl.AddEvents( "'mouseout'" );
    lbl.On( "mouseover", "function(p) { alert('in') }" );
    lbl.On( "mouseout", "function(p) { alert('out') }" );
    I tried with and without the AddEvent calls. I tried adding a listener to the 'click' event this way and that didn't do the trick either. I tried adding the listener instead to the panel, and still nada. I may have done something blatently wrong, but I believe the above is essentially the same code at the beginning of this posting.

    So, to work-around this problem, the other option from this posting overcame:
    
    
    
    string fn = "Ext.get('" + lbl.ClientID + "').on('mouseover',function(p) { alert('in') });";
    this.ScriptManager1.RegisterOnReadyScript( fn );
    Though, I suspect both should have worked the same.

    Another side-note, you might want to assert when clientID is null when you call addListener because the String.Format call in AddListner puts ClientID in {0} and it's not created automatically if dynamically created.

Similar Threads

  1. Replies: 6
    Last Post: Jan 18, 2013, 4:22 AM
  2. Replies: 12
    Last Post: Dec 25, 2012, 11:55 AM
  3. Replies: 2
    Last Post: Jul 29, 2012, 12:19 PM
  4. Replies: 3
    Last Post: May 03, 2012, 3:33 PM
  5. [CLOSED] Adding events to custom control
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 29, 2012, 8:16 PM

Posting Permissions