|
I want to navigate from one control(e.g textbox) to another(textbox) by pressing Return or Enter key in a web application developing by asp.net.How can it be possible? Now it is possible by pressing Tab key.
|
|
|
I don`t know if .Net throws anything into the mix or not, but talking strictly HTML and Javascript, here are some tips on how to capture when the Return/Enter key is pressed. I don`t recommend altering the default way that users navigate in web pages, but I certainly understand wanting to make your application more data-entry friendly! Here is some javascript to get you started. Unfortunately, the tabs and line breaks may not appear correctly.
<script language=javascript1.2>
var isIE = (navigator.appName.indexOf(""Microsoft"") != -1);
function KeyUpTrigger() {
if (isIE) {
thekey = window.event.keyCode;
if((thekey == 13) && (this.type != `textarea`)) {
//Enter key was pressed, do what you want.
alert("Enter key was pressed.");
}
}
}
function LoadTrigger() {
// Create a global onkeyup event trigger.
for(i=0;i<(document.forms[0].elements.length);i++) {
document.forms[0].elements.onkeyup = KeyUpTrigger;
}
}
window.onload = LoadTrigger;
</script>
Let me explain this script. The first thing is that we set a variable to indicate true if the browser is Internet Explorer. We need to know this because the keyCode property only works in IE. (Don`t know any methods to do this in Netscape.) Now let`s go from the bottom up. window.onload = LoadTrigger; sets it so the LoadTrigger() function runs as soon as the page has loaded. LoadTrigger() contains code that loops through every element of the first form of your page (you can change the 0 to a 1, 2, etc if you need to apply to other forms. This loop assigns the function KeyUpTrigger() to fire on every onkeyup event of every element in your form. You could manually type "onkeyup=KeyUpTrigger()" into each form field if you prefer, but this loop does it automatically. Only thing left is the KeyUpTrigger() function. This function looks for keycode = 13 (the Return key). It also makes sure that the field in question is not a textarea because you want your users to be able to use the Return/Enter key normally inside a textarea. Then put whatever code you want inside this function.
Another tip: If you want to disable the default form submit that can happen when you press Enter, place this in your form tag: onsubmit="return false;" Like so:
<form method=post onsubmit="return false;" action="/forum/ProcessForm.html">
This means you must submit your form using javascript (document.forms[0].submit() .
I hope this made sense--I know it can be cryptic. Just let me know if you`d like further explanation.
|
|
|
|
|
Navigation
In ASP.NET 2.0, a menu can be stored in a file to make it easier to maintain. This file is normally called web.sitemap, and is stored in the root directory of the web.
Basically ASP.NET 2.0 has three navigation controls:
(1) Dynamic menus
(2) TreeViews
(3) Site Map Path
The Sitemap File
A sitemap file is an XML file stores the structured listing of site navigation links. Here is the format looks like.
<?xml version="1.0" encoding="iso-8859-1" ?>
<siteMap>
<siteMapNode title="Home" url="/aspnet/w3home.html">
<siteMapNode title="Services" url="/aspnet/w3services.html">
<siteMapNode title="Training" url="/aspnet/w3training.html"/>
<siteMapNode title="Support" url="/aspnet/w3support.html"/>
</siteMapNode>
</siteMapNode>
</siteMap>
----------------------------------------------------- flash banner|logo maker|flash menu|drop down menu
|
|
|
|
|
|
|
|