Visual InterDev
When you write scripts, you can manipulate various objects to perform application tasks. For example, in a client script you might:
In a server script you work with different objects, which you might manipulate in order to:
The objects that you can use in a script depend on the context in which the script will run. If you are working in server script, you can use only the objects available on the server. Conversely, if you are writing a client script, you can only use objects that are part of the page, are available to the browser, or that you know exist on the client computer.
Note If you use the scripting object model and design-time controls, you can use the same script objects whether you are working with client script or server script. For details, see Scripting with Design-Time Controls and Script Objects.
In client scripts, you can get properties and call methods for objects on the page and write event handlers for them. For example, the following small script displays the title of the current document using the alert
method of the window
object and the title
property of the document
object:
<SCRIPT LANGUAGE="VBScript">
alert(document.title)
</SCRIPT>
Each object has its own methods and properties, which you can use as required. In client scripts, most objects also support events for which you can write handlers. For example, you can write a handler for a button's onclick event to control what happens when the button is clicked.
The exact objects and events that are available in a client script depend on the object model available in the browser your users will be using. For example, in some browsers you can write a script that changes the text on the page, but not all browsers support that feature. In general, you can rely on the following:
When you write script, it is a good idea to limit yourself to the object model supported by your users' browsers. For example, if you know that most of your users will be using Internet Explorer 3.0 (or another browser that supports HTML 3.2), you should not make your application dependent on DHTML features. Alternatively, you can write your application to test for a particular browser and then expose features based on what browser the user has. For information about testing browser capabilities, see Creating Portable Script.
The following table lists common client objects available in HTML 3.2.
Object | Description |
window |
Browser object that allows you to determine information about the browser, prompt the user for information, and display messages. The two commonly used events onload and onunload allow you to perform initialization tasks when a document is loaded. |
document |
Browser object that allows you to set document colors, determine the URL of the current and referring document, get the document's title, and write text into the page. For more information about writing text, see Displaying Information to the User. |
form |
Browser object that allows you to determine information about a form's method and action, and enumerate the elements in the form. You can write handlers for the form's submit event in order to specify what happens when the user clicks the submit button. For more information about using forms, see Gathering Information Using Forms. Tip Visual InterDev provides design-time controls and a FormManager control that allow you to create forms easily without writing scripts for the HTML <form> object. For details, see Scripting with Design-Time Controls and Script Objects and Creating Event-Driven Forms. |
element |
Individual form elements such as buttons, text boxes, and so on. You can write handlers for element events such as being clicked, getting or losing focus, and changing. For more information, see Gathering Information Using Forms. Tip You can use Visual InterDev design-time controls instead. For details, see Scripting with Design-Time Controls and Script Objects. |
Java Applets, ActiveX controls | Objects created externally and added to the page. Applets are placed onto a page in an <APPLET> block, and objects in an <OBJECT> block. Applets and ActiveX controls support their own set of properties, methods, and events for which you can write handlers. |
If you are writing a script that will run on Microsoft® Internet Information Server, you can use objects that are intrinsic to the server, such as the server's Request and Response objects. You can also use components that are bundled with the server, but not an inherent part of it, such as the AdRotator component, the BrowserCapability component, and ActiveX Data Objects (ADO). Finally, you can use any other object that is registered on the server, including components that you create and register yourself.
Tip You can easily create your own components using Windows script components. For details, see Packaging Script as Objects.
Using server objects and components is a very powerful feature of Visual InterDev. When you create Web applications, you usually cannot control what browser the user has or what controls are registered on the user's computer. By installing controls on the server and using them in server script, you make the features of those controls available to any user, no matter what browser is in use.
When you are writing server script, you cannot directly manipulate client objects such as the browser window, an HTML form, Java applets, or DHTML objects, because these objects do not reside on the server.
If you are working with the server's intrinsic controls such as the Request or Response objects, you can simply reference the objects in your script, as in this example:
<%Server("starttime") = time%>
However, for all other objects, you create the object. You can do so by using an <OBJECT> tag in which you specify the attribute RUNAT=SERVER. Creating an <OBJECT> tag allows you to reference the object in any server script on the page, and adds the object and its members to the IntelliSense® statement completion drop-down list. For example, the following creates an object reference to an ADO connection object:
<OBJECT RUNAT="Server" ID=cn PROGID="ADODB.Connection">
</OBJECT>
In your script, you can reference this object using the name you assigned in the ID attribute. The following statements use the object defined in the <OBJECT> block:
cn.Open Application("ConnectionString")
' other processing here
cn.Close
Alternatively, you can create objects with the CreateObject method of the Server object to create an instance of the object, as in the following statement:
<%
Set Ad = Server.CreateObject("MSWC.Adrotator")
Ad.GetAdvertisement("/ads/adrot.txt")
%>
For an example, see the Random Advertisement Sample in the Sample gallery.
The following table lists common server objects and components.
Object | Description |
Request |
Intrinsic IIS object that provides access to any information passed into the script through an HTTP request, such as form information, search strings, browser information, and information stored in cookies. For more information and examples of using the Request object, see Gathering Information Using Forms, Sharing Dynamic Information, and Creating Portable Script. |
Response |
Intrinsic IIS object that sends information to the user by writing information into a Web page stream or to the user's browser. For more information and examples of using the Response object, see Navigating Conditionally and Sharing Dynamic Information. |
Session, Application |
Intrinsic IIS objects that allow you to set and get values that persist between pages in your Web application. For more details, see Sharing Dynamic Information. |
Server |
Intrinsic IIS object that allows you to create instances of objects that are registered on the server, including bundled components and objects that you create. |
AdRotator, BrowserCapability, TextStream, and NextLink |
Components that are bundled with IIS, and allow you to display a changing set of images, store and get information about specific browsers, read and write to text files, and create an ordered path through pages. |
ActiveX Data Objects (ADO) |
Bundled components that allow you to connect to and query databases. For information and examples, see Database Tasks, Database Samples, and ADO Overview. |