Author: Builder.com 2005-01-12 09:50 AM
ASP.NET provides new examples for Web program development. These include a series of servers-based controls, which are similar to those such as text boxes, buttons, and more in the HTML form. The problem with these controls is to call the server. JavaScript provides a variety of options for many tasks, and these processes do not need to call servers. Let us look at the power of JavaScript and ASP.NET.
Performance is a required call server requires bandwidth and server processing time, however there will not have any problems with a local area network program that can enjoy high-speed circulation, but in a wide area network is different. A Internet user connection speed depends primarily on the user's dial-up modem, bandwidth or cable modem. Using a user-type JavaScript can not call the server.
Traditional methods A standard web form includes a page like a header box, a body, and a form. The JavaScript function is placed on the web form of the web form, which allows these functions to be loaded and utilized by other parts of the page. Once they are loaded, these functions will be called from the HTML element. Let's take a look at a simple JavaScript example:
Function Valsubmit () {var Doc = Document.Forms [0]; varmsg = "; if (doc.firstname.value ==") {
MSG = "- please enter a first name.n";
IF (Doc.lastname.Value == "") {msg = "- please enter a last name.n";}
IF (msg == ") {doc.submit ();} else {Alert (" The followinger ";}}
This function will be verified to two HIML zones in the form. If one of the zones is empty, the error message will be displayed and the operation is stopped. If the form is submitted, you can call this function using the following code: Using this relationship, the form will not be submitted before the HIML area is not data. This way we can see that the code becomes simpler, but because there is no need to call additional servers without any side effects. JavaScript is short and practical, which means that the form does not require additional load time.
Combine JavaScript and ASP.NET to ASP.NET web forms Allow use of standard HTML, so you can easily use the previous example. ASP.NET User Control allows you to easily call server code to handle web forms. Fortunately, the combination of user controls and JavaScript is completely available. I will use an example of an ASP.NET button control to illustrate this process.
All properties of the button control provide ways to connect JavaScript to the control. First, place the JavaScript function in the ASP.NET web page form, but the placement can be changed by adding a return value. If confirmed, the function value is returned to true, and the server function related to the button will be called. If the return value is false, the form will not be submitted.
<% @ Page language = "c #"%>