Wednesday, March 28, 2012

Extender Control properties in a switch/case

Hello,

I have problems using properties of an Extender Control in a switch/case selection.

I wrote an ASP.NET AJAX Extender Control to control a GridView with keyboard shortcuts. For that, the user can configure declaretively what keys to use for e.g. paging in the GridView. The key values are mapped to properties in the JavaScript part of the Extender Control (Sys.UI.Behavior class).

In a handler function I determine which key the user has pressed and call the porper _postBack. This works fine with if/else, e.g. if (KeyEvent.keyCode == this._delKeyCode). But with switch/case, e.g. switch (KeyEvent) { case this._delKeyCode: ... break; .. the pressed key is not determined and nothing happens with the GridView. There are also no JavaScript errors. It seems, that with switch/case a control property can't be determined as with if/else.

Thank You

Regards

Rolf

The switch should be:

switch (KeyEvent.keyCode) {
case this._delKeyCode:
// Something
break;
}

-Damien


Thanks Damien,

but sorry it is a typo in my post. I'am actually using

switch (KeyEvent.keyCode) instead ofswitch (KeyEvent) as I wrote. So I'am actually using the switch statement you suggest.

Regards

Rolf


My only guess why it isn't working is because you are comparing against a variable (e.g. this._delKeyCode), try using the actual numeric key code...

-Damien

No comments:

Post a Comment