Friday, 3 February 2012

HTML Server Controls | ASP.Net Tutorial | ASP.Net Tutorial PDF

     HTML server controls are outwardly identical to plain old HTML tags, but include a runat="server" attribute. This gives the ASP.NET runtime control over the HTML server controls, allowing us to access them programmatically. For example, if we have an <a> tag in a page and we want to be able to change the address to which it links dynamically, using VB or C# code, we use the runat="server" attribute.
     A server-side HTML server control exists for each of HTML’s most common elements. Creating HTML server controls is easy: we simply stick a runat="server"attribute on the end of a normal HTML tag to create the HTML control version of that tag. The complete list of current HTML control classes and their associated tags is given in below Table.
Table
   All the HTML server control classes are contained within the System.Web.UI.HtmlControls namespace. As they’re processed on the server side by the ASP.NET runtime, we can access their properties through code elsewhere in the page. If you’re familiar with JavaScript, HTML, and CSS, you’ll know that manipulating text within HTML tags, or even manipulating inline styles within an HTML tag, can be cumbersome and error-prone. HTML server controls aim to solve these problems by allowing you to manipulate the page easily with your choice of .NET language for instance, using VB or C#.

Web Forms | ASP.Net Tutorial | ASP.Net Tutorial PDF

     As you know, there’s always new terminology to master when you’re learning new technologies. The term used to describe an ASP.NET web page is web form, and this is the central object in ASP.NET development. You’ve already met web forms—they’re the .aspx files you’ve worked with so far in this book. At first glance, web forms look much like HTML pages, but in addition to static HTML content they also contain ASP.NET-specific elements, and code that executes on the server side.

    Every web form includes a <form runat="server"> tag, which contains the ASP.NET-specific elements that make up the page. Multiple forms aren’t supported. The basic structure of a web form is shown here:

<%@ Page Language="language" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
⋮ code block…
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Page Title</title>
</head>
<body>
<form id="form1" runat="server">
⋮ user interface elements…
</form>
</body>
</html>
  
     To access and manipulate a web form programmatically, we use the System.Web.UI.Page class. You might recognize this class from the code-behind example we saw in Chapter 3. We must mention the class explicitly in the code-behind file. In situations in which we’re not using code-behind files (that is, we’re writing all the code inside the .aspx file instead), the Page class is still used—we just don’t see it.

       We can use a range of user interface elements inside the form—including typical, static HTML code—but we can also use elements whose values or properties can be generated or manipulated on the server either when the page first loads, or when the form is submitted. These elements—which, in ASP.NET parlance, are called controls—allow us to reuse common functionality, such as the page header, a calendar,
a shopping cart summary, or a “Today’s Quote” box, for example, across multiple web forms. There are several types of controls in ASP.NET:
  • HTML server controls
  • web server controls
  • web user controls
  • master pages
   There are significant technical differences between these types of controls, but what makes them similar is the ease with which we can integrate and reuse them in our web sites. Let’s take a look at them one by one.

Constructing ASP.NET Web Pages | ASP.Net Tutorial | ASP.Net Tutorial PDF

  If you’ve ever built a model from Lego bricks, you’re well prepared to start building real ASP.NET web pages. ASP.NET offers features that allow web developers to build parts of web pages independently, then put them together later to form complete pages.
    The content we’re creating through our work with ASP.NET is almost never static. At design time, we tend to think in terms of templates that contain placeholders for the content that will be generated dynamically at runtime. And to fill those placeholders, we can either use one of the many controls ASP.NET provides, or build our own.
     In this chapter, we’ll discuss many of the objects and techniques that give life and color to ASP.NET web pages, including:
  • web forms
  • HTML server controls
  • web server controls
  • web user controls
  • master pages
  • handling page navigation
  • styling pages and controls with CSS
     If the list looks intimidating, don’t worry—all of this is far easier to understand than it might first appear.

C# | ASP.Net Tutorial | ASP.Net Tutorial PDF

      The official line is that Microsoft created C# in an attempt to produce a programming language that coupled the simplicity of Visual Basic with the power and flexibility of C++. However, there’s little doubt that its development was at least hurried along by Microsoft’s legal disputes with Sun. After Microsoft’s treatment (some would say abuse) of Sun’s Java programming language, Microsoft was forced to stop developing
its own version of Java, and instead developed C# and another language, which it calls J#. We’re not going to worry about J# here, as C# is preferable. It’s easy to read, use, and maintain, because it does away with much of the confusing syntax for which C++ became infamous.

Visual Basic | ASP.Net Tutorial | ASP.Net Tutorial PDF

The latest version of Visual Basic is the result of a dramatic overhaul of Microsoft’s hugely popular Visual Basic language. With the inception of Rapid Application Development (RAD) in the 1990s, Visual Basic became extremely popular, allowing in-house teams and software development shops to bang out applications hand over fist. The latest version of VB has many advantages over older versions, most notably the fact that it has now became a fully object oriented language. At last, it can call itself a true programming language that’s on a par with the likes of Java and C++. Despite the changes, VB generally stays close to the structured, legible syntax that has always made it so easy to read, use, and maintain.

ASP.NET Languages | ASP.Net Tutorial | ASP.Net Tutorial PDF

    As we saw in the previous chapter, .NET supports many different languages; in fact, there’s no limit to the number of languages that could be supported. If you’re used to writing ASP 2.0 or ASP 3.0, you may think the choice of VBScript or JScript would be an obvious one. But, with ASP.NET, Microsoft did away with VBScript, merging it with Visual Basic. ASP.NET’s support for C# is likely to find favor with developers from other backgrounds. This section will introduce you to both these new languages, which will be covered in more depth in the next chapter. By the end of this section, you’ll likely agree that the similarities between the two are astonishing any differences are minor and, in most cases, easy to figure out.

    Traditional server technologies are much more constrained in terms of the development languages they offer. For instance, old-style CGI scripts were typically written with Perl or C/C++, JSP uses Java, Coldfusion uses CFML, and PHP is a technology and a language rolled into one. .NET’s support for many different languages lets developers choose the ones they prefer. To keep things simple, this book will consider
the two most popular: VB and C#. You can choose the language that feels more comfortable to you, or stick with your current favorite if you have one.

Working with Directives | ASP.Net Tutorial | ASP.Net Tutorial PDF

   For the most part, ASP.NET pages resemble traditional HTML pages with a few additions. In essence, just using the .aspx extension for an HTML file will ensure that IIS passes the page to the .NET Framework for processing. However, before you can work with certain, more advanced features, you’ll need to know how to use directives.
    We talked a little about directives and what they can do earlier in this chapter. You learned that directives control how a page is created, how a page is cached, help with bug-fixing, and allow us to import advanced functionality for use within our code. Three of the most commonly used directives are:

Page
This directive defines page-specific attributes for the ASP.NET page, such as the language used for server-side code. We’ve already seen this directive in use.

Import
The Importdirective makes functionality that’s been defined elsewhere available in a given page. The following example, for instance, imports functionality from the System.Web.Mail namespace, which you could use to send email from a page. Namespaces are simply .NET’s way of keeping all its functionality neatly organized.
<%@ Import Namespace="System.Web.Mail" %>
You’ll become very familiar with this directive as you work through this book.

Register
This directive allows you to register a user control for use on your page. We’ll cover Register in detail in next Topic but the directive looks something like this:
<%@ Register TagPrefix="uc" TagName="footer" Src="footer.ascx" %>