W3Schools.com

ASP.NET Web Pages - Files and Folders


Learn ASP.NET Web Pages by building a web site from scratch.

Part II: Creating standard folders and a consistent style.


What We Will Do

In this chapter we will:

  • Create a new empty web site
  • Create the necessary folders
  • Create a standard style sheet for the site
  • Create a standard layout for the site
  • Create a home page for the site

1. Start With an Empty Web Site

If you have followed this tutorial, you already have a web site called Demo.

If not you can create an empty web site with WebMatrix:

  • Start WebMatrix
  • Click on "Create Site From Template"
  • Choose "Empty Site"
  • Name the site "Demo"

2. Create Folders

In the folder named "Demo" (your website), create 5 folders:

  • Account - for storing login and membership files
  • App_Data - for storing databases and data files
  • Images - for storing images
  • Scripts - for storing browser scripts
  • Shared - for storing shared style and layout files
Folders

3. Create a Style Sheet

In the "Shared" folder, create a new style sheet (CSS file) named "Site.css".

Put the following code inside the CSS file:

Site.css

h1
{
border-bottom: 3px solid #cc9900;
font: Georgia, serif;
color: #996600;
}
body
{
font: "Trebuchet MS", Verdana, sans-serif;
background-color: #5c87b2;
color: #696969;
}
#main
{
padding: 30px;
background-color: #ffffff;
border-radius: 0 4px 4px 4px;
}

The CSS file above defines the styles to be used used for

  • The HTML heading element <h1>
  • The HTML body element <body>
  • The HTML element with id="main"

4. Create a Layout Page

In the "Shared" folder, create a new file named "Layout.cshtml".

Put the following code inside the layout file:

Layout.cshtml

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/Shared/Site.css" />
</head>
<body>

<div id="main">
@RenderBody()
<p>&copy; 2012 W3Schools. All rights reserved.</p>
</div>

</body>
</html>

The layout file above defines the layout of your web pages. It has a link to your style sheet file (Shared/Site.css), and a call to the @RenderBody() function, where page content should be displayed.


5. Create a Home Page

In your empty "Demo" folder, create a new file, named "Default.cshtml".

If you created a file with this name earlier, you can edit the existing file, or create a new file with a new name (like Default2.cshtml).

Put the following code inside the file:

Default.cshtml

@{Layout="/Shared/Layout.cshtml";}

<h1>Welcome to W3Schools</h1>

<h2>Web Site Main Ingredients</h2>

<p>A Home Page (Default.cshtml)</p>
<p>A Layout File (Layout.cshtml)</p>
<p>A Style Sheet (Site.css)</p>

Run example »

The file starts with a reference to the layout file, otherwise it contains normal HTML markup.


Congratulations

You have created your first web site, with a main page (the Default page), a common template for all your pages (the Layout page), and a common style sheet (the CSS file).

In the next chapters of this tutorial, we will add navigation to the web site. Then we will add a database, and finally we will add login and security.




W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE