Use client scriptures

xiaoxiao2021-03-06  57

Use client scriptures

Release Date: 9/20/2004

| Update Date: 9/20/2004

Scott Mitchell

4Guysfromrolla.com

Summary: Although ASP.NET performs most of its operations on the server, some operations may be better in the client. Scott Mitchell illustrates how ASP.NET pages and controls add client code.

Download the source code of this article.

This page

Introduction Creating a base class As the basis of adding a client script, adding a client script from the code hidden class to perform a client code to perform a client code to perform a client code. Related books

Introduction

When using dynamic, web-based script technology, similar to traditional ASP or PHP, developers must have a keen understanding of logic, temporary and physical separation between clients and servers. For example, for user operations executed by trigger server-side code, developers using traditional ASPs must explicitly enable the user's browser to return to the web server. Creating such an interaction may easily take up a lot of development time, and result in less read code.

Microsoft ASP.NET helps to reduce the burden of binding user events to a specific server-side code, Microsoft ASP.NET, which blurred the boundaries between the client and the server. Using ASP.NET and the least work, developers can quickly create the following web page, which has a large number of interactive user interface elements buttons, drop-down list, etc., which are based on end users, and can selectively run the server. End code. For example, use ASP.NET to add a drop-down list, as long as the selected drop-down list item change, you only need to add the DropDownList web control, set its autopostback property to true, then create a SELECTEDEXCHANGED event handler for the drop-down list. program. If you use traditional ASP to complete the above tasks, you will require many complex HTMLs, client JavaScript, and server-side code; with ASP.NET, you will provide you with the necessary scripting code and server-side event model.

Although the Web form in ASP.NET is greatly simplified in ASP.NET, it may cause unacceptable performance if you misuse this feature may result in unacceptable performance. Although the Web form hides the complexity involved, the end user's browser must return the request to the web server by re-submitting the form. When submitting a form, all form fields (text boxes, drop-down lists, and check boxes) must return their values. In addition, the view status of the page is also returned to the web server. All in all, each time a returning web page, thousands of bytes of data will need potentially send back to the Web server. Thus, regular growth may soon lead to the web application that is not available, especially for users who still use dial-up. It can reduce the needs of frequent rapid movement by pushing the function to the client.

Note ASP.NET Web Forms emit a hidden form field titled for ViewState, which contains 64-bit encoded representation based on the Web control in the web control. According to the web control, the range of view status can be from several trimesters to tens of thousands of bytes. To learn more about the status of the view, please check my article Understanding ASP.NET View State.

With traditional ASP, add data drivers, custom client scripts is very simple, but not very easy to read. For example, to display a pop-up window that loads the URL according to a ID field in a conventional ASP, you can use the syntax to insert the value of the ID field and enter in the appropriate client script. ASP.NET allows you to create this data-driven client script using various methods in the Page class. This paper analyzes technology to add client scripts to the ASP.NET web page. The client script is the script code running in the Visitor's browser, as indicated by its name. We will see how to complete common client tasks, such as display a warning, confirmation box, and pop-up window. (One main purpose of the client script field verification may be a bit irrelevant to the ASP.NET topic, because the verification program web control provides a client window to experience with the accessibility.) The focus of this article is inserted into the client script Server terminal class, method, and technology; we will not analyze the actual client script in detail, because the information involves numerous articles and sites around the Web.

Back to top

Creating a base class as the basis for adding a client script

One of the main differences between the traditional ASP and ASP.NET is the programming model of the respective technologies. The ASP page is atomic, the script on the program, explains access to each page. However, ASP.NET is completely object-oriented programming technology. All ASP.NET web pages are classes with properties, methods, and events. All web pages are derived from the PAGE class in the System.Web.ui namespace, and the page class contains the basic features of the ASP.NET web page.

One of the concepts of object-oriented programming is to inherit. Inheritance allows you to create a new class that extends other class features. (If class B inherits class A, it can also be expanded A; class A is called a base class.) When using code hidden models to create an ASP.NET web page, you can see the code hidden class inherited Page class. :

Public Class Webform1

Inherits System.Web.ui.page

...

END CLASS

By keeping your code hidden class inherits the page class, it automatically receives the functions inherited in the Page class, such as Request, Response, Session, and ViewState objects, such as init, load, render, and more. We will see in this article, if you need a common feature that can be used for all ASP.NET web pages, a method is class that creates other methods and attributes that are sent from the Page class and have these required enhancements. Then, you want the ASP.NET web page to utilize these enhancements, we only need to update the page code hide the inherits statement in the class to use the class extension Page class.

In this article, we will create a class named ClientSidePage, which derives the Page class and provides additional methods to assist in performing a common client task. Adding a script code will be as simple as the script code will be as simple as the script code will be as simple as the calling method and the transmission of several parameters. Specifically, the class includes methods for the following uses:

• Display the Mode Client dialog. • Set the focus to a specific form field when loading the page. • Use the Mode Determine dialog to determine if the user wants to return to the form. • Display the pop-up window.

Before we study the ClientsidePage class, let us analyze the relevant methods in the Page class to insert the client script into the web page. After we discuss these Page methods, we will start to extend their features with the ClientSidePage class, and see how to combine all content together and how to use extensions in the ASP.NET web page.

Back to top

Add a client script from the code hidden class

All ASP.NET web pages must be derived directly or indirectly from the PAGE class in System.Web.ui namespace. The Page class contains the basic set of methods, properties, and events required by the normal running web page. In many ways to this class, some methods are intended to insert the client script into the generated HTML. These methods are called from code hidden class, so they can be used to issue a data-driven client script. The related PAGE method used to issue a client script is as follows. The base class is derived from the System.Web.ui.page class, so you can access them by calling the Page class directly from the code hidden class.

Note To access the Page class, you can type the method name directly, or by entering mybase. (For Microsoft Visual Basic .NET), this. (For C #) or Page. (For C # or Visual Basic .NET), using Microsoft IntelliSense in Visual Studio .NET is implemented. If you use Visual Basic .NET as a selected programming language, make sure that Visual Studio .NET is configured to not hide advanced members, you will not be able to see these client scripts. (To display advanced members, go to Tools | Options | TextEditor | Basic, then clear Hide Advanced Members checkbox.)

RegisterClientScriptBlock (Key, Script)

After the WEB form has been presented

element, the RegisterClientScriptblock method adds a client script block before any web control included in a web form. The key input parameter allows you to specify a unique key associated with the script, and the Script parameter includes a complete script code to be issued. (This Script parameter should include the actual