Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to capture enter event in asp.net

Posted on 2011-09-07
6
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

715 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