240 likes | 450 Views
Module 1: Working with ASP.NET. Overview. Introducing ASP.NET Creating Web Forms Adding ASP.NET Code to a Page Handling Page Events Discussion: ASP vs. ASP.NET. Introducing ASP.NET. The .NET Framework ASP.NET Features Animation: The ASP.NET Execution Model. ADO.NET: Data & XML.
E N D
Overview • Introducing ASP.NET • Creating Web Forms • Adding ASP.NET Code to a Page • Handling Page Events • Discussion: ASP vs. ASP.NET
Introducing ASP.NET • The .NET Framework • ASP.NET Features • Animation: The ASP.NET Execution Model
ADO.NET: Data & XML Base Class Library Web Services UserInterface Common Language Runtime Visual Studio.NET Orchestration .NET Framework .NET EnterpriseServers Building Block Services Internet COM+ Windows The .NET Framework
ASP.NET Features • Multiple Language Support • Increased Performance • Compiled code • Cache • Classes and Namespaces • Server Controls • Web Services
ASP.NET Features (continued) • Improved Security • Greater Scalability • Cookie-less Sessions • Easy Configuration and Deployment
Creating Web Forms • What Are Web Forms? • What Are Server Controls? • Types of Server Controls • How Do Server Controls Work? • Demonstration: Adding Server Controls to an ASP.NET Page
What Are Web Forms? • .aspx extension • @Page Directive • Framework Is an Object Model • Denoted by the runat="server" Attribute • Contain Client-side and Server-side Code • Contain HTML and Server Controls <%@ Page Language=“C#" %> <Form runat="server"> </Form>
What Are Server Controls? • Server-programmable Objects • Denoted by Tag with the runat = "server" Attribute • Encapsulate Both Behavior and Rendering • Fully Declarative • Render Different HTML to Support Multiple Browsers or other Web Clients
Types of Server Controls • HTML Controls • Exist within the System.Web.UI.HtmlControls namespace • Web Controls • Exist within theSystem.Web.UI.WebControls namespace <input type="text" id="txtName" runat="server"> <span id="spnStarter" runat="server"> starter</span> <asp:TextBox id="txtName" runat="server" Text="[Entry Keywords]"/>
How Do Server Controls Work? • Declared with runat="server" Attribute • When the ASP.NET Page is Executed: • Creates action and method attributes of form • Adds unique id and name attributes to controls • Adds value attribute to controls • Adds a hidden control to the form to save view state information <input type="text" id="text2" runat="server">
Adding ASP.NET Code to a Page • Creating ASP.NET <SCRIPT> Section • Creating Event Procedures • Demonstration: Adding Code to Controls
Creating ASP.NET <SCRIPT> Section • Declaring the Language • Declaring Functions and Subroutines <script language="VB" runat="server"> <script language="C#" runat="server"> <SCRIPT LANGUAGE="VB" runat="server"> Sub login () 'contents of routine End Sub </SCRIPT>
Creating Event Procedures • Assign a Method Name to the Event Attribute • Create an Event Procedure in Your Page Code • Access Properties of Controls in the Event Procedure <input type="submit" value="Submit!" onServerClick="GreetMe" runat="server"> Sub GreetMe(s As Object, e As EventArgs) Sub GreetMe(s As Object, e As EventArgs) spnGreeting.InnerHTML = "Hello " & _ txtName.Value End Sub
Handling Page Events • Page Event Life Cycle • Handling Postback Forms • Demonstration: Using Postback Forms
Page Event Life Cycle Page_Init Page is disposed Page_Load Textbox1_Changed Button1_Click Page_Unload
Handling Postback Forms • ViewState Control Maintains the State of a Page During Postback • Page_Load Fires on Every Request • Use Page.IsPostBack to execute conditional logic Sub Page_Load(s As Object, e As EventArgs) If Not Page.IsPostBack Then 'executes only on initial page load End If 'Rest of procedure executes on every request End Sub
Review • Introducing ASP.NET • Creating Web Forms • Adding ASP.NET Code to a Page • Handling Page Events • Discussion: ASP vs. ASP.NET