Solved

How to capture enter event in asp.net

Posted on 2011-09-07
6
205 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now