Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to capture enter event in asp.net

Posted on 2011-09-07
6
Medium Priority
?
215 Views
Last Modified: 2012-05-12
Hi

I want to capture the enter event in a multiline text box in asp.net 3.5 and want to store that data in SQL databasse,So that when i fetch that data in future it would be shown un the same format with proper spacing
0
Comment
Question by:ASPNET_8
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36494791
<asp:TextBox ID="User_IDTextbox" Rows="3" Columns="50" TextMode="MultiLine" onkeypress="checkEnter(event)" runat="server"></asp:TextBox>

and ur JS function will be

function checkEnter(event)
{
     if (!event) event = window.event;
     key = event.keyCode ? event.keyCode : event.which;    

     if (key == 13)  //13 is keycode for enter key
     {
       //do stuff here.
     }
}

0
 

Author Comment

by:ASPNET_8
ID: 36494821
Can u pls explain me what does this code do??

This part

 if (!event) event = window.event;
     key = event.keyCode ? event.keyCode : event.which;  
0
 

Author Comment

by:ASPNET_8
ID: 36494845
How would i store the data in this Multiline text box with proper sppacing and retrieve it from there in the same format.??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1000 total points
ID: 36494846
window.event contains which key is pressed. In IE event.keyCode contains the value (While pressing enter the value will be 13). But in browsers such as firefox event.which will contain the value. This code to work with all browsers.
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 36494976
That javascript listens for the enter key which is only part of the solution. Inside the javascript that easwaranp provided, put code that adds "\r\n" to the textbox. This will give the newline in place of the enter.

If you just wanted the newline to write in the textbox from the codebehind you could use Environment.NewLine
VB.NET
txtTest.Text = "First Line " & Environment.NewLine & "Second Line"

C#
txtTest.Text = "First Line " + Environment.NewLine + "Second Line";
0
 

Author Closing Comment

by:ASPNET_8
ID: 36586084
good
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question