Combining JavaScript with asp.net Web Forms for program development

Source: Internet
Author: User
Tags functions html form net require return

ASP. NET provides a new paradigm for Web application development. This includes a series of server-based controls that resemble elements such as text boxes, buttons, and so on in an HTML form. The problem with these controls is that you must call the server. JavaScript provides multiple choices for many tasks, and these processes do not require a call to the server. Let's look at the powerful features that combine JavaScript with asp.net.

Performance is required
The calling server requires bandwidth and server processing time, while there will be no problem with a LAN program that can enjoy high-speed flow, but it is different in the WAN. The difference in the speed of an Internet user's connection depends primarily on the user's dial-up modem, bandwidth, or cable modem. User-type JavaScript can be used without calling the server.

Traditional methods
A standard Web page form includes pages such as title boxes, body text, and forms. JavaScript functions are traditionally placed in the title box of the page form, which allows the other parts of the page to be loaded and exploited, and once loaded, these functions are invoked from the HTML element.

Let's take a look at a simple example of javascript:

function Valsubmit () {
var doc = document.forms[0];
Varmsg = "";

if (Doc.firstName.value = = "") {

msg + + "-Please enter a-NAME.N";
}

if (Doc.lastName.value = = "") {
msg + + "-Please enter a NAME.N";
}

if (msg = = "") {
Doc.submit ();
} else {
Alert ("The following errors were
Encountered.nn "+ msg);
}
}
This function transmits the validation data to the two HIML areas in the form. If one of the zones is empty, an error message is displayed and the operation stops. If the form is committed when all two extents have a value, you can call the function using the following code:


1<input type= "button" value= "Submit" Name= "Btnsubmit" onclick= "Valsubmit" (); >

With this relationship, the form is not committed until the HIML area has no data. As we can see, the code becomes simpler, but there is no side effect because there is no need to invoke additional servers. JavaScript is short and practical, which means that the form does not require additional loading time.

Combining JavaScript with asp.net
Asp. NET Web page forms allow you to use standard HTML, so you can easily use the previous example. Asp. NET user controls allow you to easily invoke server code to work with Web Forms. Thankfully, the combination of user controls and JavaScript is entirely possible. I'll use an example of a ASP.net button control to illustrate the use of this process.

All of the properties of the button control provide a way to connect JavaScript to the control. First, you place the JavaScript function in the ASP.net Web page form, but you can change the placement by adding the return value. If confirmation passes, the function value is returned to true, and the server function associated with the button is not invoked. If the return value is false, the form is not committed.

Total 2 page: previous 1 [2] Next page



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.