0% found this document useful (0 votes)
142 views9 pages

Homework-4 OF Web Programming: Submitted To

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 9

HOMEWORK-4

OF
WEB PROGRAMMING
[INT-302]

SUBMITTED TO:
MR. ANUPINDER SINGH

SUBMITTED BY:
KRITIKA GOYAL
B.TECH-IT
1070070173
RB2701A10
PART-A

QUES1: Request and Response objects are used to handle transition between browser and
server. How?

ANS1: Response Object: The ASP Response object is used to send output to the user from the server. Its
collections, properties, and methods are described below:

• COLLECTION: Some of the collection of the response object are as follows:

o Cookies: Sets a cookie value. If the cookie does not exist, it will be created, and take the value
that is specified.

• PROPERTIES: Some of the properties of the response object are as follows:

o Buffer: Specifies whether to buffer the page output or not.

o Cache control: Sets whether a proxy server can cache the output generated by ASP or not.

o Charset: Appends the name of a character-set to the content-type header in the Response object.

o Contenttype: Sets the HTTP content type for the Response object.

o Expires: Sets how long (in minutes) a page will be cached on a browser before it expires.

• METHODS: Some of the methods of the response object are as follows:

o Addheader: Adds a new HTTP header and a value to the HTTP response.

o AppendToLog: Adds a string to the end of the server log entry.

o Clear: Clears any buffered HTML output.

o End: Stops processing a script, and returns the current result.

o Flush: Sends buffered HTML output immediately.

Request Object: When a browser asks for a page from a server, it is called a request. The Request object is
used to get information from a visitor. Its collections, properties, and methods are described below:

• COLLECTIONS: Some of the collections of request object are as follows:

o QueryString: Contains all the variable values in a HTTP query string.


o Form: Contains all the form (input) values from a form that uses the post method.
o ClientCertificate: Contains all the field values stored in the client certificate.
o ServerVariable: Contains all the server variable values.

• PROPERTIES: Some of the properties of request object are as follows:

o TotalBytes: Returns the total number of bytes the client sent in the body of the request.
• METHODS: Some of the methods of request object are as follows:

o BinaryRead: Retrieves the data sent to the server from the client as part of a post request and
stores it in a safe array.

QUES2: There are various events defined in global.asa file. Discuss them?

ANS2: The Global.asa file is an optional file that can contain declarations of objects, variables, and methods
that can be accessed by every page in an ASP application.

All valid browser scripts (JavaScript, VBScript, JScript, PerlScript, etc.) can be used within Global.asa.

In Global.asa we can tell the application and session objects what to do when the application/session starts and
what to do when the application/session ends. The code for this is placed in event handlers.

The Global.asa file can contain four types of events which are as follows:

Application_OnStart - Occurs when the FIRST user calls the first page in an ASP application. This event
occurs after the Web server is restarted or after the Global.asa file is edited. The "Session_OnStart" event occurs
immediately after this event.

Session_OnStart - This event occurs EVERY time a NEW user requests his or her first page in the ASP
application.

Session_OnEnd - This event occurs EVERY time a user ends a session. A user-session ends after a page has
not been requested by the user for a specified time (by default this is 20 minutes).

Application_OnEnd - This event occurs after the LAST user has ended the session. Typically, this event
occurs when a Web server stops. This procedure is used to clean up settings after the Application stops, like
delete records or write information to text files.

The main point is that we cannot use the ASP script delimiters (<% and %>) to insert scripts in the Global.asa
file, we put subroutines inside an HTML <script> element.

QUES3: Create a web page using a basic HTML, which contains a link or a button which
opens a page after a delay of 15 seconds. Elaborate the process for implementing the same.

ANS3: While creating a web page using basic HTML, which contain a link or button which opens a page after
a delay of 15seconds, we create the page with the help of java script. Under the script tag we make a user
defined function let this function be abc(). In javascript there is an in built function sleep(). This function is used
to give a time break by default it takes the time in minutes, but according to the required condition of the given
page we need a delay of 15seconds, so we convert the time from minutes into second. Then the function abc() is
called in the form by using onclick. When we click on the button after the delay of 15 seconds it open the page.
The coding for the given condition is as follows:

CODING:

<html>
<head>

<script language="javascript">

function abc()

sleep(0.25);

document.write("<a href="colors.html">');

</script>

</head>

<body>

<FORM>

<INPUT TYPE="submit" VALUE="Clickable Button" onclick="abc()">

</FORM>

</body>

</html>

PART-B

QUES4: How do you make a dynamic select box using ASP?

ANS4: The code for creating a dynamic select box using ASP is as follows:
<%@ language = "Javascript" %>

<SCRIPT language = "Javascript">


<%
var path;
var conn = Server.CreateObject("ADODB.Connection");
path = Server.Mappath("../database.mdb");
var RS = Server.CreateObject("ADODB.RecordSet");
conn.Open("database");
RS.ActiveConnection = conn;
%>
</SCRIPT>

<HTML>
<HEAD>
<SCRIPT LANGUAGE = "Javascript">

function Init()
{
Select1();
}

function Select1()
{
<% var SQL = "";
var Val1 = "";
var Val2 = "";
var i = 0;

SQL = "SELECT Table1ID, Table1Name FROM Table1"


RS.Open(SQL,conn);

while (!RS.EOF)
{
Val1 = RS.Fields("Table1ID");
Val2 = RS.Fields("Table1Name");
Response.Write("document.MainForm.Dropdown1[" + i + "] = new Option('" + Val2 + "','" + Val1 + "');");
RS.MoveNext();
i++;
}
RS.Close();
%>
}

<% var Selected; %>

function Select2(Selected)
{
<%
var SQL = "";
var Val1 = "";
var Val2 = "";
var i = 0;

SQL = "SELECT Table2ID, Table2Name FROM Table2 WHERE Table2ID = '" + Selected + "'"
RS.Open(SQL,conn);

while (!RS.EOF)
{
Val1 = RS.Fields("Table2ID");
Val2 = RS.Fields("Table2Name");
Response.Write("document.MainForm.Dropdown2[" + i + "] = new Option('" + Val2 + "','" + Val1 + "');");
RS.MoveNext();
i++;
}
RS.Close();
%>
}
</SCRIPT>
</HEAD>

<BODY onload="Init();">
<form name = "MainForm">
<table width="440" cellpadding="0" cellspacing="2" border="0" height="196">
<tr>
<td width="110" align="center" valign="top" height="170">
<select size="9" name= "Dropdown1"
onchange="Select2(document.MainForm.Dropdown1.options[document.MainForm.Dropdown1.selectedIndex].
value);">
</select>
</td>
<td width="110" align="center" height="170" valign="top">
<select size = 9 name = "Dropdown2">
</select>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>

QUES5: Analyze the concept of ActiveX controls and which programming languages are
used to write ActiveX controls?

ANS5: ActiveX is a framework for defining reusable software components (known as controls) that perform a
particular function or a set of functions in Microsoft Windows in a way that is independent of the programming
language used to implement them. A software application can then be composed from one or more of these
components in order to provide its functionality.[1]

It was introduced in 1996 by Microsoft as a development of its Component Object Model (COM) and Object
Linking and Embedding (OLE) technologies and it is commonly used in its Windows operating system,
although the technology itself is not tied to it.

Many Microsoft Windows applications — including many of those from Microsoft itself, such as Internet
Explorer, Microsoft Office, Microsoft Visual Studio, and Windows Media Player — use ActiveX controls to
build their feature-set and also encapsulate their own functionality as ActiveX controls which can then be
embedded into other applications. Internet Explorer also allows embedding ActiveX controls onto web pages.

ActiveX controls — small program building blocks — can serve to create distributed applications that work
over the Internet through web browsers. Examples include customized applications for gathering data, viewing
certain kinds of files, and displaying animation.

One can compare ActiveX controls in some sense to Java applets: programmers designed both these
mechanisms so that web browsers could download and execute them. However, they also differ:

• Java applets can run on nearly any platform, while ActiveX components officially operate only with
Microsoft's Internet Explorer web browser and the Microsoft Windows operating system.[2]
• Programmers can grant to ActiveX controls a much higher level of control over Windows than Java
applets ever achieve, making them both more powerful but also potentially more dangerous.

Malware, such as computer viruses and spyware, can be accidentally installed from malicious websites using
ActiveX controls (drive-by downloads). Signed Java applets can also be used for such attacks, although this is
rare.

Programmers can write ActiveX controls in any of the following languages/environments:

• MFC
• ATL
• C++
• C#
• Borland Delphi
• Visual Basic

Common examples of ActiveX controls include command buttons, list boxes, dialog boxes, and the Internet
Explorer browser.

QUES6: Create a HTML page in which there is a login screen in which user enters
information. The information gets saved in the database. Convert it using some Dynamic
setup under ASP.NET.

ANS6: The code to save the information direct in the database which is entered by the user using asp.net
is as follows:

Using system.data.sqlclient;

Public partial class_default: system.web.vi.page

Sqlconnection con=new sqlconnection();

Protected void page_load(object sender,eventargs e)

{
Con.connectionstring=configurationmanager.connectionstrings[“kritika”].connectionstring;

If(con.state==connectionstate.closed)

Con.open();

Button1_click

Sqlcommand cmd=new sqlcommand();

cmd.command text=”insert into tlogin values(@ud,@pass)”;

cmd.connection=con;

cmd.parameters.add(“@ud”,sqldbtype.varchar,50).value=textbox1.text;

cmd.parameters.add(“@pass”,sqldbtype.varchar,50).value=textbox2.text;

cmd.executenonquery();

cmd.dispose();

con.close();

LAYOUT OF HTML PAGE:

<html>

<head>

<title>login</title>

</head>

<body>

<form runat=”server”>

<table>

<tr>

<td>User Name</td>

<td><asp:textbox type=”text” id=”textbox1” maxlength=”20” runat=”server”/></td>


</tr><br><br>

<tr>

<td>Password</td>

<td><asp:textbox type=”password” id=”textbox2” maxlength=”20” runat=”server”/></td>

</tr><br><br>

<tr>

<td></td>

<td><asp:button id=”button1” name=”Submit” runat=”server”/>&nbsp; &nbsp; &nbsp;

<asp:button id=”button2” name=”Cancel” runat=”server”/></td>

</tr>

</table>

</form>

</body>

</html>

You might also like