Saturday, October 17, 2009

DomEvents in ASP.NET AJAX

In my previous article Avoid Numbers in Textbox using ASP.NET AJAX, I showed how you can prevent numbers from being entered into a Textbox, using ASP.NET AJAX Framework.

In that example, the code segment e.charCod  and preventDefault() designates a property belonging to Sys.UI.DomEvent class. The Sys.UI is the class provided by the AJAX Framework to work with the DOM components in a webpage. And you can say, Sys is the root namespace or mother-of-all classes, just like System is the root namespace in C#.

After a slight Binging, I’s able to get a lot more properties of the Sys.UI.DomEvent class. Please note, they are cross-browser objects. Here is the list:

Properties Descriptions
rawEvent event-data object built by the current browser
shiftKey Returns TRUE, if SHIFT key was pressed
ctrlKey Returns TRUE, if CTRL key was pressed
altKey Returns TRUE, if ALT key was pressed
button captures the mouse-button click and has values as (leftButton, middleButton and rightButton)
charCode character code for the typed characters
clientX returns the  x-coordinate of the mouse location relative to client area of the page
clientY returns the  y-coordinate of the mouse location relative to 
client area of the page
target represents the Element that raised the event
screenX x-coordinate of mouse-pointer relative to screen
screenY y-coordinate of mouse-pointer relative to screen
type Returns name/type of the event (click/mouse)
preventDefault() Prevents the default action associated with that event
stopPropagation() Prevents the event from propagation to  the element’s parent nodes

Hope this is handy.

No comments:

Best viewed in Internet Explorer 8.