codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  navigation of control  Archive Import (zahidBang) at 11:01 on Monday, July 14, 2003
 

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.

  Re: navigation of control  Troy Wolf at 16:32 on Friday, August 01, 2003
 

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.

Troy Wolf: site expert
SnippetEdit Website Editor


  Re: navigation of control  Elain at 07:39 on Friday, November 26, 2010
 

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








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: How to check number of fields in form?
•  Re: where can i post my programs to the world?
•  Re: DHTML tabletree
•  Re: Needed script or whatever it is
•  Re: navigation of control
•  Re: Image on a HTML button
•  Re: Trouble w/strings in ASP
•  Re: how to print a report having many records.
•  Re: Creating a simple client login / email database


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010