This blog is moved to

Thursday, July 3, 2008

Asp.Net Multiline TextBox + Default Button

Hi guys,

I got into this interesting problem while developing a chat web client.
Basically i was trying to do some POC. Since i haven't had enough
time with me, i used a multiline textbox as the chat input element.

And the send button is set as the default button.
Since the textbox is multiline, if we press enter key,
as its behavior it will produce a newline inside the textbox.

What i want is to fire the send button event.

For that i wrote the following JavaScript.

sendText.Attributes.Add("onkeydown", "javascript: return keydownHandler('"+ sendBtn.ClientId + "')");

function keydownHandler(sendBtnId)
if(event.which || event.keyCode)
if ((event.which == 13) || (event.keyCode == 13))
return false;
return true

No comments: