Thursday, February 21, 2008

Q. Types of CSS?

There are three types of CSS styles:

inline styles
Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to.
a href="" style="text-decoration: none;"
embedded styles
Embedded styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in.
style type="text/css"
p { color: #00f; }
/style
external styles
External styles are styles that are written in a separate document and then attached to various Web documents. External style sheets can affect any document they are attached to.
link rel="stylesheet" type="text/css" href="styles.css" /
CSS best practices recommends that you use primarily external style sheets for styling Web pages so that you get the most benefit of the cascade and inheritance.

Q. What are ASP Objects?

Objects to reduce these repetitive tasks. An object is a collection of functionality and information. ASP has given us a handfull of Intrinsic Objects.

Object Used For
Request : Getting information from the User
Response : Sending information to the User
Session : Storing information about a User's Session
Application : Sharing information for the entire application
Server : Accessing the server resources

Request Object
This object is mainly used to retrieve the information from the from in a HTML Page.
The Request Object has the following Collections:
- Form - To access value from a form submitted using POST method.
- QueryString - To access varibales sent with URL after "?" or from a from submitted using GET method.
- Cookies - To access the value of a Cookie.
- ServerVariables - To access information from HTTP Headers.
The syntax to access the variables of any of these collections is Request.Collections("Variables").

Response Object

This object is used to send information to the user ( i.e. to the browser).
The most used methods of Response object are:
- Write - Used to send information to be displayed on the browser.
- Redirect - Used to send the user to a new Page.
The syntax to use these method is Response.Method
Eg: Response.Redirect("newpage.html")

Session Object

This object is used to store information with a scope to that user session. The information stored are maintained even when the user moves through various pages in the web application.
The session object has two properties.
- SessionID - Created by the web application and sent as a cookie to client.
- TimeOut - To set Session timeout period.
The session object has one method, Abandon. This method is used to explicitly close the session and hence destroying the session object.
You can create new variables with session scope using the following syntax:
Session("Variablename")=Value
And the same can be referred using the following syntax:
Session("Variablename").

Application Object

This object is used to share information among the users of the web application. The variable becomes alive, when the first request to the application comes in.
This object is typically used to create variables that need to maintain application level scope.
The Application object has the following methods:
- Lock- To Lock the variable
- Unlock - To unlock the variable
Since the application variables can be accessed by all the users of the application, the lock and unlock method is used to avoid more than one user accessing the same variable.
You can create new variables with Application scope using the following syntax:
Application("Variablename")=Value.
And the same can be referred using the following syntax:
Application("Variablename").

Server Object

This object gives access to Server components,its methods and properties.
This object has the following methods:
- CreateObject - An important method used to create instance of Server Components
- HTMLEncode - To HTML encode a string passed
- URLEncode - To URL encode the string.
The CreateObject is a very important method and it is widely used in most ASP Pages.The syntax to use any of these methods is Server.Method.
For Eg:
Server.CreateObject("ADODB.Connection")

What is ADO?
ADO is a Microsoft technology
ADO stands for ActiveX Data Objects
ADO is a Microsoft Active-X component
ADO is automatically installed with Microsoft IIS
ADO is a programming interface to access data in a database

Accessing a Database from an ASP Page
The common way to access a database from inside an ASP page is to:
Create an ADO connection to a database
Open the database connection
Create an ADO recordset
Open the recordset
Extract the data you need from the recordset
Close the recordset
Close the connection

Before a database can be accessed from a web page, a database connection has to be established.

Create a DSN-less Database Connection
The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access database on your web site.
If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you can connect to the database with the following ASP code:
%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%

The ADO Connection Object
The ADO Connection object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database

To be able to read database data, the data must first be loaded into a recordset.

an ADO Table Recordset
After an ADO Database Connection has been created, as demonstrated in the previous chapter, it is possible to create an ADO Recordset.
Suppose we have a database named "Northwind", we can get access to the "Customers" table inside the database with the following lines:
%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%

ADO Display

The most common way to display data from a recordset, is to display the data in an HTML table.

ADO Command Object

Command Object
The ADO Command object is used to execute a single query against a database. The query can perform actions like creating, adding, retrieving, deleting or updating records.
If the query is used to retrieve data, the data will be returned as a RecordSet object. This means that the retrieved data can be manipulated by properties, collections, methods, and events of the Recordset object.
The major feature of the Command object is the ability to use stored queries and procedures with parameters.

ADO Connection Object

The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.
If you want to access a database multiple times, you should establish a connection using the Connection object. You can also make a connection to a database by passing a connection string via a Command or Recordset object. However, this type of connection is only good for one specific, single query.

ADO Error Object

The ADO Error object contains details about data access errors that have been generated during a single operation.
ADO generates one Error object for each error. Each Error object contains details of the specific error, and are stored in the Errors collection. To access the errors, you must refer to a specific connection.

ADO Field Object

The ADO Field object contains information about a column in a Recordset object. There is one Field object for each column in the Recordset.

ADO Parameter Object

The ADO Parameter object provides information about a single parameter used in a stored procedure or query.
A Parameter object is added to the Parameters Collection when it is created. The Parameters Collection is associated with a specific Command object, which uses the Collection to pass parameters in and out of stored procedures and queries.
Parameters can be used to create Parameterized Commands. These commands are (after they have been defined and stored) using parameters to alter some details of the command before it is executed. For example, an SQL SELECT statement could use a parameter to define the criteria of a WHERE clause.
There are four types of parameters: input parameters, output parameters, input/output parameters and return parameters.

Q. Discuss ASP FileSystemObject Object?

ASP FileSystemObject Object

The FileSystemObject object provides access to the file system on the web server, allowing us to manipulate text files, folders and drives from within our code. The properties and methods of the FileSystemObject object are as follows:

Properties Description
Drives The Drives property returns a collection of all Drive objects on the computer. This includes network drives that are mapped from this machine. You can iterate through this property with the For...Each...Next construct.
Methods Description
BuildPath The BuildPath method adds the file or folder name to an existing path.
CopyFile The CopyFile method copies one or more files from one folder to another.
CopyFolder The CopyFolder method copies one or more folders from one folder to another.
CreateFolder The CreateFolder method creates a new folder. An error occurs if this folder already exists.
CreateTextFile The CreateText File method creates a new text file and returns a TextStream object that refers to it.
DeleteFile The DeleteFile method deletes one or more specified files.
DeleteFolder The DeleteFolder method deletes one or more specified folders.
DriveExists The DriveExist method determines whether specified drive exists. Returns True if the specified drive exists, or False if not.
FileExists The FileExist method determines whether specified file exists. Returns True if the specified file exists, or False if not.
FolderExists The FolderExist method determines whether specified folder exists. Returns True if the specified folder exists, or False if not.
GetFile The GetFile method returns a File object for a specified path. This can be a relative or absolute path to the required file.
GetFileName The GetFileName method returns the file name or the last folder name in a specified path. It does not check for existence of the file or folder.
GetFolder The GetFolder method returns a Folder object for a specified path. This can be a relative or absolute path to the required folder.
GetParentFolderName The GetParentFolderName method returns the name of the parent folder of the file or folder in a specified path.
GetSpecialFolder The GetSpecialFolder method returns a Folder object corresponding to one of the Windows' special folders.
GetDrive The GetDrive method returns a Drive object of a specified path.
GetDriveName The GetDriveName method returns the drive name in a specified path. This can be an absolute path to a file or folder, or just the drive letter such as "c:" or just "c".
GetAbsolutePathName The GetAbsolutePathName method returns the full path from the root of the drive for the specified path.
GetBaseName The BaseName method returns the base name of a specified file or folder, i.e. with the path and file extension removed.
GetExtensionName The GetExtensionName method returns the file extension name in a specified path.
GetTempName The GetTempName method returns a randomly generated file of folder. This method only returns a temporary filename but does not create the actual file.
MoveFile The MoveFile method moves one or more files from one location to another. This method is similar to the File object's Move method, but no File object is required.
MoveFolder The MoveFolder method moves one or more folders from one location to another.
OpenTextFile The OpenTextFile method creates a new file or opens an existing one, and returns TextStream object that refers to it. You can then read from, write to, or append to this file.

Q. Differentiate between ASP Application Object and Session Object?

ASP Application Object

An Active Server Page application is actually a collection of ASP files in a virtual directory and associated sub-directories. The Application object is used to control and manage all items that are available to all users of an Active Server application. The Application items can be variables needed for all users in the application, or they can be instantiated objects that provide special server-side functionality.
The Application object is initialized by IIS when the first .asp page from within the given virtual directory is requested. It remains in the server's memory until either the web service is stopped or the application is explicitly unloaded from the web server (using the Microsoft Management Console).


ASP Session Object
The Session object stores information needed for a particular user's session on the web server. It is automatically created every time when an ASP page from the web site or web application is requested by a user who does not already have a session, and it remains available until the session expires.
The Session object is user specific. It can be used to store variables specific to a particular user and IIS will maintain these variables when the client moves across pages within your web site.
The Session object is based on using cookies, so if cookies are not permitted on the client browser (because of firewall issues, browser incompatibility, or desktop/network security concerns), the Session object is rendered useless.

No comments: