Referencing a YUI object from an event handler

by timvasil 10/30/2007 3:19:00 PM

I'm just getting started with the YUI JavaScript framework.  My first task was to wrap YUI TabView control with an ASP.NET control so I could easily design and manage it from the server side.  Part of this task involved tracking the selected tab. 

It's easy enough to hook the appropriate event:

new YAHOO.widget.TabView('id').addListener('activeTabChanged', tabViewChangeHandler);

But how do I, from the handler, get a reference to the YUI TabView object?  I need a reference to the object so I can get its ID and the set a hidden field to record the currently selected tab.

As it turns out, the this keyword conveniently enough references the TabView object within event handler functions.  Cool!  So recording the selected tab in a hidden field is pretty easy:

tabViewTabChangeHandler : function(oEvent)
{
    var sTabViewId = this.get('element').id;
   
var sTabId = oEvent.newValue.get('contentEl').id;
   
var oTabIdField = YAHOO.util.Dom.get(sTabViewId + "_sel");
   
oTabIdField.value = sTabId;
}

 

Tags: ,

ASP.NET

Comments are closed

Search

Calendar

«  February 2012  »
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

View posts in large calendar

Recent comments

Archive