180 likes | 311 Views
Module 3: Creating a Microsoft ASP.NET Web Form. Creating Web Forms Adding Server Controls to a Web Form Creating Master Pages. INSPIRING CREATIVE AND INNOVATIVE MINDS. Lesson: Creating Web Forms. What Is a Web Form? Creating a Web Form by Using Visual Studio 2008. What Is a Web Form?.
E N D
Module 3: Creating a Microsoft ASP.NET Web Form • Creating Web Forms • Adding Server Controls to a Web Form • Creating Master Pages INSPIRING CREATIVE AND INNOVATIVE MINDS
Lesson: Creating Web Forms • What Is a Web Form? • Creating a Web Form by Using Visual Studio 2008
What Is a Web Form? • Web Forms have the following features: • .aspx extension • Page attributes • @ Page directive • Body attributes • Form attributes <%@ Page Language=“C#" CodeFile=“NewForm.aspx.cs" Inherits=“NewForm" %> <html> <body> <form id=“form1" runat="server"> </form> </body> </html>
Creating a Web Form by Using Visual Studio 2008 • Create a new Web application • Default Web Form for a new application: Default.aspx • Add additional Web Forms to an existing application • In Solution Explorer user the Add New Item dialog box
Lesson: Adding Server Controls to a Web Form • What Is a Server Control? • Types of Server Controls • Saving View State • HTML Server Controls • Web Server Controls • Discussion: Selecting the Appropriate Control
Server controls: Contain runat="server" attribute Events happen on the server View state saved Provide built-in functionality Provide a common object model All have ID and Text attributes Create browser-specific HTML What Is a Server Control? <asp:Button ID="Button1" runat="server" Text="Submit"/>
Types of Server Controls • HTML server controls • Web server controls • Intrinsic controls • Validation controls • Rich controls • List-bound controls • Login controls
Saving View State • View state • Control state • Use view state to maintain the control's contents • Use control state to maintain the core behavior of the control • HiddenField control <asp:ListBox ID="ListName" EnableViewState="true" runat="server"> </asp:ListBox>
HTML Server Controls • Based on HTML elements • Exist in the System.Web.UI.HtmlControls namespace <input type="text" id="txtName" runat="server" />
Web Server Controls • Exist in the System.Web.UI.WebControls namespace • Control syntax • HTML that is generated by the control <asp:TextBox id="TextBox1" runat="server">Text_to_Display </asp:TextBox> <input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/>
Discussion: Selecting the Appropriate Control • Is it ever appropriate to use HTML server controls instead of Web server controls?
Lesson: Creating Master Pages • What Are Master Pages? • Content Pages • Runtime Behavior of Master Pages • Discussion: Advantages of Master Pages
What Are Master Pages? • Master pages provide a simple method to create a consistent layout across a Web site • Master pages have the following features: • File extension of .master instead of .aspx • @ Master directive instead of the @ Page directive • ContentPlaceHolder controls, which define the areas where the replaceable content appears • Top-level HTML elements for a page, such as html, head, and form • Master pages can be nested
Content Pages • Content pages are Web pages that reference a master page • MasterPageFile attribute in @ Page directive • Content pages have their own page-specific content <%@ Page Language="C#" MasterPageFile="~/benefitsMaster.master" AutoEventWireup="true" CodeFile="contentPage.aspx.cs" Inherits="contentPage" %>
Runtime Behavior of Master Pages Master Page Content Page Resulting Web Page
Discussion: Advantages of Master Pages • What are the advantages of master pages in a Web application?
Lab: Creating a Microsoft ASP.NET Web Form • Exercise 1: Creating the Default.aspx Web Form • Exercise 2: Creating the benefitsMaster Master Page • Exercise 3: Creating the life.aspx Web Form Estimated time: 30 minutes
Lab Scenario Master PagebenefitsMaster.master Logon Page login.aspx BenefitsHome PageDefault.aspx Lab Web Application ASPState Page Headerheader.ascx Menu ComponentBenefits.cs or Benefits.vb Registration register.aspx TempDB Web.config Life Insurancelife.aspx Retirementretirement.aspx Medicalmedical.aspx Dentistsdental.aspx Prospectusprospectus.aspx XML Web ServiceDentalService1.asmx Doctorsdoctors.aspx User ControlnameDate.ascx LINQ to SQLClassesDoctors.dbml Dentists Doctors XML Files