Solved

How to capture enter event in asp.net

Posted on 2011-09-07
6
207 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Core index.html  LOCALHOST page cannot be found 2 53
Server Error 11 58
Message not shown 5 50
Need to start a web service from Visual Studio 2015 Pro 2 24
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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