inspiring creative and innovative minds
DESCRIPTION
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?. - PowerPoint PPT PresentationTRANSCRIPT
INSPIRING CREATIVE AND INNOVATIVE MINDS
Module 3: Creating a Microsoft ASP.NET Web Form
•Creating Web Forms
•Adding Server Controls to a Web Form
•Creating Master Pages
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>
<%@ 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
What Is a Server 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
<asp:Button ID="Button1" runat="server" Text="Submit"/><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>
<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" /><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>
<asp:TextBox id="TextBox1" runat="server">Text_to_Display </asp:TextBox>
<input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/><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" %>
<%@ 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
Medicalmedical.aspxMedicalmedical.aspx
BenefitsHome PageDefault.aspx
BenefitsHome PageDefault.aspx
Life Insurancelife.aspxLife Insurancelife.aspx
Retirementretirement.aspxRetirementretirement.aspx
Dentistsdental.aspxDentistsdental.aspx
Doctorsdoctors.aspx Doctorsdoctors.aspx
Logon Pagelogin.aspxLogon Pagelogin.aspx
Registrationregister.aspxRegistrationregister.aspx
Prospectusprospectus.aspxProspectusprospectus.aspx XML Web
ServiceDentalService1.asmx
XML Web ServiceDentalService1.asmx
Page Headerheader.ascxPage Headerheader.ascx
Lab Web Application
User ControlnameDate.ascxUser ControlnameDate.ascx
Menu ComponentBenefits.cs or Benefits.vbMenu ComponentBenefits.cs or Benefits.vb
Master PagebenefitsMaster.masterMaster PagebenefitsMaster.master
LINQ to SQLClassesDoctors.dbml
LINQ to SQLClassesDoctors.dbml
ASPState
DentistsDoctorsXML Files
Web.config
TempDB