European ASP.NET Hosting Tutorial – How to Use JavaScript to Avoid Submit Page in Text Box

Normally in the controls like Text box at ASP.NET Webform, whenever you press enter key it will submit the page. In other words, it will post the page back to the server. In this post, we are going to explain different ways how to avoid this by using JavaScript.

How to Use JavaScript to Avoid Submit Page in Text Box

#1. Insert the JavaScript Directly to The Markup

In this way, you need to include the “onkeydown” event on each text box control.

#2. Insert JavaScript Through Server Side Code

If you want to achieve the above one in server side, that is you loop through the controls and inject the same javascript snippet. For this, you can use the following markup and code behind:

Markup:

Code behind:

#3. Using JQuery

In the above two techniques, either we need to include the same line in each control or we need to loop through the controls and inser the JavaScript. In some cases you may want to achieve the same using jQuery.

Simple Right?

Looking for ASP.NET Hosting on European Server? We can help you a lot!

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

hostforlifebanner

(Visited 49 times, 1 visits today)

HostForLIFE.eu is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. HostForLIFE.eu offers a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers. The company’s prices for shared and dedicated hosting are competitive; its features and perks are robust;