03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

62 x CHAPTER 2 BUILDING AN <strong>ASP</strong>.<strong>NET</strong> WEBSITE<br />

How It Works<br />

L<strong>in</strong>ks between pages are likely one of the most important elements <strong>in</strong> a web page, because they enable<br />

you to create a connection between a page <strong>in</strong> your site <strong>and</strong> another page, whether that page lives <strong>in</strong><br />

your own site or on a completely different server somewhere on the Internet. For simple l<strong>in</strong>ks that<br />

should appear somewhere <strong>in</strong> your page, the HTML tag with an href attribute set is the easiest to<br />

set up. When the user clicks such a l<strong>in</strong>k, the browser requests the new page from the server <strong>and</strong> displays<br />

it. The double dots (..) <strong>in</strong> the href’s value are a way to refer to the parent directory. The full href<br />

attribute means “go up one level <strong>in</strong> the folder hierarchy <strong>and</strong> then select the file Default.aspx.” You see<br />

a lot more about l<strong>in</strong>ks <strong>and</strong> how they work <strong>in</strong> Chapter 7.<br />

You’re not limited to l<strong>in</strong>k<strong>in</strong>g to pages <strong>in</strong> your own site. If you want to l<strong>in</strong>k to external pages <strong>in</strong>stead,<br />

simply replace the href attribute value with the full address of the page, as shown <strong>in</strong> the follow<strong>in</strong>g<br />

example:<br />

Go to the Wrox homepage<br />

For external l<strong>in</strong>ks, it’s important to <strong>in</strong>clude the http:// prefix; otherwise, the browser goes out look<strong>in</strong>g<br />

for a file or folder called www.wrox.com on your own website.<br />

You’ll use the th<strong>in</strong>gs you learned <strong>in</strong> this chapter about page creation <strong>and</strong> formatt<strong>in</strong>g <strong>in</strong> the next<br />

chapter, which deals with design<strong>in</strong>g your web pages us<strong>in</strong>g CSS.<br />

Besides the visual tools, like the Formatt<strong>in</strong>g toolbar <strong>and</strong> the Table menu, Visual Studio has another<br />

great way to quickly <strong>in</strong>sert code <strong>in</strong> your pages: code snippets. Code snippets enable you to <strong>in</strong>sert<br />

large chunks of code with just a few keystrokes. You see code snippets at work <strong>in</strong> the next chapter.<br />

PRACTICAL TIPS ON WORKING WITH WEB FORMS<br />

Here are some tips for work<strong>in</strong>g with Web Forms:<br />

‰ Favor Web Forms with Code Beh<strong>in</strong>d over those with <strong>in</strong>l<strong>in</strong>e code. Although at first you may<br />

not notice a big difference <strong>in</strong> work<strong>in</strong>g with them, as your site <strong>and</strong> pages start to grow, you’ll<br />

f<strong>in</strong>d that it’s easier to work with a page where the code is separated from the markup.<br />

‰ Spend some time familiariz<strong>in</strong>g yourself with the different menu items of the Format <strong>and</strong><br />

Table menus. Most of them generate HTML elements that are <strong>in</strong>serted <strong>in</strong>to your page. Take<br />

a look at the HTML elements <strong>and</strong> attributes that have been generated for you, <strong>and</strong> try to<br />

change them directly <strong>in</strong> the code, <strong>and</strong> through the menus <strong>and</strong> toolbars. This way, you get a<br />

good feel for the various tags available <strong>and</strong> how they behave.<br />

‰ Experiment with l<strong>in</strong>ks to connect pages <strong>in</strong> your site. Notice how VS creates different l<strong>in</strong>ks<br />

depend<strong>in</strong>g on the location of the page you are l<strong>in</strong>k<strong>in</strong>g to. Chapter 7 deals with l<strong>in</strong>k<strong>in</strong>g <strong>and</strong><br />

the various ways to address pages <strong>in</strong> your site <strong>in</strong> much more detail.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!