Multiline TextBox and Default Button in ASP.NET

Posted By  amalhashim On 22 Apr 2010 11:04:57
emailbookmarkadd commentsprint
No of Views:785
Bookmarked:0 times
Votes:0 times

Introduction

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 enoughtime 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))
{
document.getElementById(sendBtnId).click();
return false;
}
}
else
{
return true
}
} 

 

that's all.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top