How to vs.net/c# Builder Web page can also realize the function of DOS input data carriage return line

Source: Internet
Author: User
Tags contains html page reference
Data | How the Web page in the Vs.net/c# Builder development of the Web page can also realize the DOS input data carriage return line function
The Institute of Economic and Information Research, Beijing Coal Research Center, St.

In the DOS era, we used to enter data when the input after a row of data to knock a carriage return to the next line of data entry. The glory of the former DOS has become the past, now more user-friendly GUI graphical interface Windows has entered our daily life.
The appearance of the 1996 Windows95 is a great revolution in the history of software. Windows is a graphic mode of operating system developed by Microsoft, which overcomes some of the commands that are difficult to remember in DOS, makes the computer more intimate with people, and the computer completes an action if you click the mouse lightly. At the same time, Windows also changed the original DOS input data to enter the way, now if we want to enter data when the cursor jump to the next line or the next input box can only press the TAB key on the keyboard or with the mouse click the next input box. This change may not have much impact on computer users who have no access to the DOS operating system, but for the turn from the DOS of the computer users is a chicken ribs; In particular, our data entry personnel, in the DOS era has been accustomed to enter a row of data to knock back to continue the next line of data entry. It is also a matter for us developers to look after the habits of these old users.
The author in a recent project has encountered such a problem: the user asked us to provide the front page input to support the function of line-wrapping. People who have been developed know that it is not too difficult to implement carriage return lines in a traditional Windows application, and we can achieve this by intercepting the keyboard's return key value, and then by sending a message to get the input focus on the next control in the input interface (such as text box input box). We can also set the focus of a Web control in a script (JavaScript or VBScript) language on a Web page.
When implementing carriage return wrapping in a Web application written in a traditional ASP or jsp/php, our usual practice is to control the onkeypress event, The onclick event or the onsubmit in the page writes a piece of JavaScript or VBScript code that captures the key value of the keyboard return, and then implements a carriage return line for the specified jump order, a disadvantage that applies only to page control elements where few items are small. Once a page control element or a large number of such files, this manual method is bound to consume a lot of work. Can there be an effective way to make us once and for all? This is the author of this article to discuss the content. You reader, let me slow down:
Our project is developed with VB.net, the front entry interface is the vb.net program compiled HTML page, run in the browser. Vb. NET development program The biggest advantage is that the program code can be isolated from the interface, that is, independent of each other, but the vb.net developed by the program generated HTML input interface of the control element name is difficult to determine, although there will be a certain naming rules. We were unable to know the name of the input control element on the compiled build page before compiling.
So we have a problem, does it mean that we want to implement DOS carriage return line function only open one ASPX file to see the element name, and then in ASP or jsp/php in the practice of writing the appropriate JavaScript or VBScript code it? This is obviously a fainting fact; we have hundreds of ASPX files on this project, and to open hundreds of files one by one, writing JavaScript or VBScript carriage return code in ASP or jsp/php is an anecdote. The author found the solution by checking MSDN and repeated practice.
I will use the JavaScript scripting language as an example to solve this problem, before writing the code I have to introduce some relevant knowledge; The paging file browsed in the browser is called a Document object (DOM) in JavaScript. There are several "big" objects in the range that JavaScript can cover: window, Document, Location, Navigator, screen, History, and so on. The Window object is the parent object of the document, location, and history objects.
Around the problem we want to solve, here we will focus on document, Form, elements three objects, and onkeypress events, documents Document object: Refers to the documentation that describes the current window or the specified Window object. It contains the contents of the document from The following is the final implementation code list:
var jumptypearray =new Array ("text", "Password", "textarea", "checkbox", "Radio",
"Select", "Select-one", "Select-multiple", "file")//reference page to get the focus element type
var debartypearray =new Array ("Submit", "Reset", "button", "checkbox", "Radio",
"Select", "Select-one", "Select-multiple", "hidden")//reference page to exclude element types
function Instrarray (SRC,DEC)
{//check if the given string is in the specified string array, as in the return index number, or no return-1;
for (var i=0; i<dec.length; i++)
{
if (Src==dec[i])
{
Return i;//positioned successfully, returns index number
Break
}
}
return-1; Location failed, return-1
}
function CHECKCR (EVT)
{//Carriage return response function
var evt = (evt)? EVT: ((event) event:null);
var node = (evt.target)? Evt.target: ((evt.srcelement)? evt.srcElement:null);
var frm=document.forms[0]; Specifies that the form name is called the first in the page
if ((Evt.keycode =) && (Instrarray (Node.type,jumptypearray)!=-1))
{//To determine whether the current object is an input object, an array of object types: Jumptypearray
for (var i = 0; i < frm.elements.length; i++)
{//for begin
if (frm.elements[i].name==node.name)
{//Locate current Object
if ((i+1) < frm.elements.length)
{//Object array index offside judgment
if (Instrarray (Frm.elements[i+1].type,jumptypearray)!=-1)
{//To determine whether the next object of the current object is an input component, an array of object types: Jumptypearray
Frm.elements[i+1].focus ()//Set focus
if (Instrarray (Frm.elements[i+1].type,debartypearray) ==-1)
{//filter non-selected text object, object type array: Debartypearray
Frm.elements[i+1].select ()//Select component text content
}
}
Return false;//prohibit submission of form content
Break
}
Else
{//Submit form Content
return true;
Break
}
}
}//end for
}
}
document.onkeypress = CHECKCR;

Reference Description: Save the above code as a file, such as: Webenter.js, and then write in the page where you want to implement the carriage return line:
<script language= "JavaScript" src= "Path+webenter.js" ></script>.
Path: is the path where the Webenter.js file resides.

Applicable environment: windows9x/nt/2000/xp+asp/jsp/php/asp.net+ie4.x (and the above version)

Precautions:
1, the reference page can not have more than one form (form).
2, the reference page is not allowed to have duplicate objects (object).

Call Example: http://dbs.myrice.com/dbs/Demo.html

The last thing to note is that when the reference page is browsed in the NS series browser, the code above needs to be modified because there is a difference between the browser object in the NS and the object in IE, which is left to the reader practicing.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.