Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 2 textboxes in a web form:
- txtInitialValue
- txtCalculatedValue

When I fill out txtInitialValue and push Enter, I want this to happen:
C#
txtCalculatedValue.Text = (myFloatParser.ToFloat(txtInitialValue.Text) * 2.5).ToString();


However, the form gets submitted every time I push Enter. I tried disabling it, and it works, BUT the drawback is I cannot trigger the txtInitialValue.TextChanged event with enter anymore.

How do I disable the Enter key from submitting the form, while at the same time allowing me to trigger TextChanged event for a textbox?
Posted
Comments
Debabrata_Das 14-Jun-14 13:14pm    
Hello friend, TextChanged is a server side event of TextBox control hence until your page is postback the event will not get triggered.
- DD
Member 8179886 14-Jun-14 13:44pm    
Ok, so I can only solve it by using javascript to register a change of focus on textbox? Or is there a better solution?

1 solution

Use JavaScript.
Attach the onkeypress event for that TextBox on which you want to press Enter key.
Check which key is pressed.
If it is Enter Key, then do your calculation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900