http://forums.asp.net/1064112/ShowPost.aspx

Hi,

behaviors are Atlas components that allows to dynamically add/remove client-side functionality from controls. For example, if I want to handle click and keypress events, I could attach the corresponding behaviors to an Atlas control. Then, if I don’t want to handle the click event anymore for that control, all I have to do is detach the corresponding behavior from the control. In this way you obtain a control with a dynamic “behavior”.

Please check this article for some details about coding an Atlas behavior.

Regarding your requirements, as bleroy suggested, Atlas has a builtin that you can use to make a control handle the click event. For the keypress event, bleroy itself and Wilco Bauwer have already coded two specific behaviors; you can click here to get the bleroy’s one and here to get the Wilco’s one.

Otherwise, if you need a very basic behavior, similar to the , here’s my version:

Type.registerNamespace('AtlasExamples.WebUI');

AtlasExamples.WebUI.KeyPressBehavior = function() {
AtlasExamples.WebUI.KeyPressBehavior.initializeBase(this);

// Private members.
var _keypressHandler;

// Events.
this.keypress = this.createEvent();

// Initialize / Dispose.
this.initialize = function() {
AtlasExamples.WebUI.KeyPressBehavior.callBaseMethod(this, ‘initialize’);

_keypressHandler = Function.createDelegate(this, keypressHandler);
this.control.element.attachEvent(’onkeypress’, _keypressHandler);

}
this.dispose = function() { �
this.control.element.detachEvent(’onkeypress’, _keypressHandler);
_keypressHandler = null;

AtlasExamples.WebUI.KeyPressBehavior.callBaseMethod(this, ‘dispose’);
}

// Descriptor.
this.getDescriptor = function() {
var td = AtlasExamples.WebUI.KeyPressBehavior.callBaseMethod(this, ‘getDescriptor’);

td.addEvent(’keypress’, true);

return td;
}

// Event Handler.
function keypressHandler() {
this.keypress.invoke(this, Web.EventArgs.Empty);
}
}
Type.registerClass(’AtlasExamples.WebUI.KeyPressBehavior’, Web.UI.Behavior);
Web.TypeDescriptor.addType(’script’, ‘keyPressBehavior’, AtlasExamples.WebUI.KeyPressBehavior);

and finally, an example that use the and the to solve your problem (just change the script reference in the ScriptManager to the correct path to the behavior file):




function onTextBoxClick() {
alert(’TextBox clicked!’);
}
function onTextBoxKeyPress() {
alert(’Key pressed in TextBox! KeyCode is ‘ + window.event.keyCode);
}