Sometimes I get annoyed when hitting the enter key in a TextBox (say login screen) resulting in undesired effects like the wrong Button being “clicked“. After so many code tricks, I found the below method that allows you to specify a default Button to submit when the user hits the enter key in a TextBox.
When you press a key on your keyboard, the js OnKeyPress event is fired. This calls a function to which we pass the id of the button associated with the TextBox. The function gets a reference to the button and simuilates a mouse-click on the Button. We perform a browser detection because IE and Netscape have different event models. The function finally returns false so that the keypress event is cancelled (otherwise a second form submit will be raised). I tried this code with newer versions of IE 6.0/Netscape 7 it worked great!.
//client side js
function clickButton(e, buttonid){
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}
//code behind
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");
The code behind generates the following code:
< input name="TextBox1" type="text" id="TextBox1" onkeypress="return clickButton(event,'Button1')" / >
This causes web control Button1 to be clicked when the enter key is hit inside TextBox1.
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Saturday, October 23, 2004
Adding Cross-Site Scripting Protection to ASP.NET 1.0
ASP.NET 1.1 added the ValidateRequest attribute to protect your site from cross-site scripting. What do you do, however, if your Web site is still running ASP.NET 1.0? This article shows how you can add similar functionality to your ASP.NET 1.0 Web sites.
Check out the article @
http://msdn.microsoft.com/library/en-us/dnaspp/html/ScriptingProtection.asp
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Check out the article @
http://msdn.microsoft.com/library/en-us/dnaspp/html/ScriptingProtection.asp
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Multilingual Support in .NET
This is a Web Solution designed to teach all newcomers into the .Net field on how to incorporate Multi-language support into your Web Applications. You have to download the accompaning ZIP file.
This tutorial will teach you
- How to create the Resource files for various languages.
- How to access the Resource file data from the web pages.
- How to store Unicode (multilingual) data into the database.
- How to access multilingual data from the database.
You can find the tutorial article at http://www.developersdex.com/gurus/articles/500.asp?Page=1
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
This tutorial will teach you
- How to create the Resource files for various languages.
- How to access the Resource file data from the web pages.
- How to store Unicode (multilingual) data into the database.
- How to access multilingual data from the database.
You can find the tutorial article at http://www.developersdex.com/gurus/articles/500.asp?Page=1
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Better Ways to Manage Your Cache in ASP.NET
Caching is one of the features in ASP.NET 1.x that most developers are familiar with. And it has helped to fuel a yearning for cache dependency in SQL Server. The ability to refresh the cache if a row in a table has been modified is very useful to a lot of developers. And hence in ASP.NET 2.0, Microsoft built SQL Server cache dependency right into the product.
Read more here http://www.devx.com/asp/Article/21751/1954?pf=true
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Read more here http://www.devx.com/asp/Article/21751/1954?pf=true
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Subscribe to:
Posts (Atom)