Recommended: ASP: Determine whether access comes from a search engine To determine whether access comes from search engine functions, if you are interested, you can try it! The following is the referenced content: <%'Check whether the current user is a Spider-Man Function check(user_agent) allows_age
Chapter 10 ASP and Client DataIs client data discussed in an ASP monograph? Is this contradictory to server-side ASP programming? This is not the case, because we have not yet met an ASP programmer who only works on server-side programming. Although ASP is a server-side technology, it is conceivable that it is impossible for programmers to program using ASP alone. Web developers engaged in ASP programming still need to interact with client data.
Therefore, when building an application around ASP, the entire application situation must be considered, which also means that the client must be considered. To get a well-run, fast-responsive application, you need to use client data well.
This chapter discusses how to use data on the client side. Special focus will be on research:
· Remote Data Services (RDS), how to transmit data to clients and receive data.
· How to bind an ADO record set to an HTML control.
· How to use user-defined components to provide data.
· How to update client data and feed it back to the server.
· How to get an image from a database and display it in a web page.
· How to create a table-based web page.
The above coverage is quite wide, and there are many different methods to achieve the same results, but it is not particularly difficult to implement.
10.1 Disconnected record set
The first thing you need to master is the concept of disconnected data. So far, in the process of studying ADO, methods for obtaining recordsets and how to modify data in these recordsets have been learned. To review, we open a record set, make some modifications to the data, and then close this record set. During the process of operating the record set, we always maintain a connection with the server. This is quite obvious, but don't forget that the web is stateless in nature. If you want to use client data, how do you always maintain a connection to the server? It's simple, this is impossible, and this is why it defines the concept of a disconnected record set.
A disconnected record set is just a normal record set, but it is unconnected to the server and becomes an isolated object. It can be updated, added, and deleted like a normal record set. But these changes only occur within the record set and are not fed back to the server, because the record set no longer has a connection to the server. This is not a disadvantage, as the connection can be re-established with the server, while the server can update any modifications. Even if the server-side data has changed, ADO still has ways for users to discover these changes in a timely manner so that users can decide which data is correct. This is called conflict resolution.
Disconnected recordsets allow us to deliver recordsets with full functionality between components, including between servers and clients. This chapter will explore how to create a disconnected record set within a component. However, we do not plan to do too detailed research on this, because Chapters 13 to 18 of this book have covered this part of the content. Here we will only give a brief introduction to how components interact with remote data services.
10.2 Remote Data Service
Remote Data Services (RDS) is a general term for a series of services that allow us to process client data. There is no need to worry about this problem now, because RDS itself is part of ADO and will only be used when client data needs to be transmitted and used. In fact, RDS is composed of several components. Figure 10-1 illustrates these components and how they work together.
Figure 10-1 Component composition of RDS
There seem to be a lot of components, but not all of them are used in every case, and there are actually some that are not part of RDS. However, all possible components are placed on the diagram here in case you need it. Figure 10-1 is divided into two parts, because using client data requires some methods to transmit data to the client. At the same time, once the data reaches the client, some methods to manage data are also required. Let's start with the server side.
10.2.1 RDS Server Components
While RDS is used to transfer and access client data, it does have some server-based components. This is necessary because there is certainly a need for some way to transfer the data to the client. Therefore, there is a series of server components that can access data and allow data to be sent to the client. We call actual data transmission marshal.
The top end of the server-side component diagram is the data storage, accessed by the OLE DB provider. It is not part of RDS, but this means that any data can be used on the client via RDS as long as there is a corresponding OLE DB provider. As for how to process data on the server, there are two options:
· DataFactory is the default server-side component for accessing data storage. It is installed on the computer as part of the server-side RDS component. In addition to obtaining data from the data storage, it also processes the data sent to and from the client for the server.
· Custom components are just ordinary COM components that provide data transfer methods. Custom components can be used when the data factory cannot provide the required functionality. This chapter introduces a simple component example, and there is a more complex example later in the book.
Web servers use these two components as interfaces to client and server data.
10.2.2 RDS Customer Components
The client starts with the DataSpace object at the bottom, which works in conjunction with the data factory or custom objects as part of the client. The DataSpace object is a proxy object that is responsible for communicating with the server and is also a channel for data transmission (or commonly known as scheduling). DataSpace objects are COM objects created in client scripting language or in HTML tags. You will see examples about this later in this chapter.
A DataSpace object is a data source object (DSO) that is responsible for storing client data. A data source object contains an ADO data record set that manages data together with the customer data cache. Customer data caching is just a customer cursor service that manages client data. At the same time, the data source object is a COM object, similar to the DataSpace object, and can also be created through client scripts or using the <OBJECT> tag in the HTML language. Similarly, some examples of this aspect will be introduced later in this chapter.
Above the data source object is the data binding manager, and the task is to establish a connection between HTML controls and data source objects. This is what we know about binding, which can be achieved by setting the DATASRC and DATAFLD properties of certain HTML controls. These are discussed below and demonstrate how to use data easily in the browser.
10.2.3 Browsers that support RDS
You should know that RDS is Microsoft's technology, so it can only work on Microsoft's browser. In fact, RDS is only fully supported in browsers with IE 4.0 or higher.
When writing applications that rely on RDS, it is important to note that the RDS version of the client accessing the application may be different from the server side. For example, RDS 1.5 is in IE 4, while RDS 2.0 is in IE 5, Office 2000 and Visual Studio 6. There are two ways to deal with this compatibility issue:
· Make sure all users have upgraded to the latest version of RDS. If the customer is running Windows 2000, then the latest version of RDS is already running. Otherwise, you can download it from the URL www.microsoft.com/data. RDS 2.5 is currently the latest version released with Windows 2000, and it is also a software package that can be downloaded separately.
· Specify the mode of the data factory when connected to a data source. This can specify which version of RDS component is used, and an example of this will be introduced later.
10.2.4 Data source object
A data source object is a client object that stores and manages client data. Because this is the easiest way to use RDS, first look at these objects.
Here are several different data source objects, each for different types of data:
· Tabular Data Control (TDC), used to process text files in table or separated form.
· RDS data control, used to connect to OLE DB datastores, can specify which datastore to connect to and which data is returned.
· Java Database Connector, a Java applet connected to data storage through Java DataBase Control (JDBC). We don't want to discuss JDBC here, because it does not provide functionality that other controls cannot achieve.
· Microsoft's HTML (MSHTML) data source object tags data with HTML and uses it as a data source.
· XML data source objects use XML data, used for structured or arbitrary structured XML.
Which data source object to choose depends on what you want to do and where the data comes from. If a small amount of data is required to be provided to the customer and the user does not allow the user to modify the data, then a table data control (TDC) may be more suitable. This data source is a text file that does not require any database, so it is relatively simple to edit. RDS data controls are the most suitable for situations where data is fetched from the database and may require updates. For many new data sources, you will find that XML data controls are needed at this time. This actually depends on the type of web application used, and the functionality required by the user.
We will introduce these data controls in turn, and once we understand how to use them to transfer data to the client, we will introduce how to use it.
Share: ASP 3.0 Advanced Programming (35) 7.5.1 General debugging techniques In Chapter 2, we have seen how to use the Response.Write method and the Request collection to display the contents of the collection. If the code wants to use the value from the request, the first thing to do is to ensure that the required value exists. The problem that is easy to occur is wrong or