This is a migrated thread and some comments may be shown as answers.

RadInput + ClientEvents.OnKeyPress + MaxLength

1 Answer 55 Views
Input
This is a migrated thread and some comments may be shown as answers.
Chris T.
Top achievements
Rank 1
Chris T. asked on 16 Dec 2011, 02:50 PM
This must be my week for strange problems.  Actually, I'm upgrading half a million lines of code from ASP.NET 2.0 to 4.0, and taking my telerik from 2009 Q3 to 2011 Q3, so I've got to catch up on 2 - 5 years of advancements.

Anyway, I'm seeing some strageness in RadInput.  I'm trying to add a specific default button for the enter key. Simple enough, right?  Handle the keypress and act on keyCode 13.

I've found through testing though, that when you have MaxLength defined on the field, characters don't seem to be accepted.  The enter key still works fine, but nothing shows up in the field.

Here's what I did:
s = string.Empty;
s += "function " + this.ClientID + "_defaultEnter(sender, eventArgs) { \r\n";
s += "  var c = eventArgs.get_keyCode(); \r\n";
s += "  var btn = document.getElementById('" + btnSearch.ClientID + "'); \r\n";
s += "  if (c == 13){ \r\n";
s += "    btn.click(); \r\n";
s += "    eventArgs.set_cancel(true); \r\n";
s += "  } \r\n";
s += "}\r\n";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.ClientID + "_defaultEnter", s, true);
fldCaseNumber.ClientEvents.OnKeyPress = this.ClientID + "_defaultEnter";

And yes, I know (now) that strings are immutable and I should be using a StringBuilder instead of += ... let's stick to the topic, eh? :)

Anyway, I can live without the MaxLength, I just wanted to share the pain and maybe help someone who can't figure out why their keyboard suddenly stopped working on that textbox.

-Chris

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 16 Dec 2011, 05:14 PM
Hello Chris,

Thank you for sharing your solution with the community.

I would make just a small comment (not sure if it will make a difference anyway), first cancel the event and then click the button.

All the best,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Input
Asked by
Chris T.
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or