How to create event handler for ASP control like Tridion control?

tridion, tridion-2011

Solution

I suspect your `onselectedindexchanged` event needs to be a `change`?

I've implemented something similar using a drop down, here are the pieces from my code. I hope this helps you to find your solution:

1) In the html / aspx page:

<select id="systemDD"></select><label for="systemDD">Select a system</label>

2) In your JavaScript:

var p = this.properties;
var c = p.controls;

// the the drop down items
c.SystemDropDown = $("#systemDD");

Adding the event handler:

$evt.addEventHandler(c.SystemDropDown, "change",
                     this.getDelegate(this._systemDropDownChanged));

The method:

EditorName.prototype._systemDropDownChanged = 
function EditorName$Extensions$EditorName$_systemDropDownChanged() {
    var p = this.properties;
    var c = p.controls;
    // get the selected system value
    var selectedSystem = $j(c.SystemDropDown).val(); 

};

I'd tackle it in the following ways:

- When you get the dropdown element, check that you have it as an object

- Try changing onselectedindexchanged to just 'change'

- A strong alcoholic drink :)

Good luck

Problem

I have an aspx page PopupReference. I am having Tridion control button and few asp controls too, like `asp:ddSelectOption` (Dropdown). So in Popupreference.js as we are creating event handler for Tridion button I am trying to create the same for my asp controls as below: This is Tridion button: ``` c.InsertButton = $controls.getControl($("#InsertButton"), "Tridion.Controls.Button"); ``` This is my dropdown: ``` c.ddSelectOption = $("#ddSelectOption"); ``` Event handler for tridion button: ``` $evt.addEventHandler(c.InsertButton, "click", this.getDelegate(this._execute)); ``` Event handler for my dropdown: ``` $evt.addEventHandler(c.ddSelectOption, "onselectedindexchanged", this.getDelegate(this._ondropdownitemchanged)); console.log('eventhandler created'); ``` I am calling the function : ``` RTFExtensions.Popups.PopupReference.prototype._ondropdownitemchanged = function PopupReference$_ondropdownitemchanged(event) { Console.log('Initializing inside dropdown...'); }; ``` But I am not able to see the last log anywhere, I think its not getting inside the function `ondropdownitemchanged(event)`. Does anyone have any clue how I can make this happen?

Original source