Chapter03

Uploaded from authorPOINTLite
Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

By: balajiraam (39 month(s) ago)

nice

Presentation Transcript

Chapter 3 - Exploring ASP.NET and Web Forms: 

Chapter 3 - Exploring ASP.NET and Web Forms

Web Forms: 

Web Forms Rendering Programming .NET Framework Extensibility WYSIWYG Code Separation State Management

Two Programming Models: 

Two Programming Models Single file programming model Good for ASP migration Code-behind (double-file) programming model Provides client/server code separation

Hello World Sample Source: 

Hello World Sample Source <%@ Page Language="vb" %> <html> <head><title>Hello World Web Page</title></head> <body> <form id="Form1" method="post" runat="server"> <asp:TextBox id="Hi" runat="server"> Hello World </asp:TextBox> <asp:Button id="Button1" runat="server" Text="Say Hi"> </asp:Button> </form> </body> </html>

Hello World Browser Source: 

Hello World Browser Source <html> <head><title>Hello World Web Page</title></head> <body> <form name="Form1" method="post" action="vb.aspx" id="Form1"> <input type="hidden" name="__VIEWSTATE" value="dDwtMTc2MjYxNDA2NTs7Pp6EUc0BOodWTOrpqefKJJjg3yEt"/> <input type="text“ name="Hi" value="Hello World" id="Hi" /> <input type="submit" name="Button1" value="Say Hi" id="Button1" /> </form> </body> </html>

Server Tag Changes: 

Server Tag Changes

Server Controls: 

Server Controls HTML Server Controls Used when: Migrating existing ASP pages to ASP.NET The Web page requires a great amount of client-side code, where client-side events need to be programmed extensively Web Server Controls More consistent interface Preferred

__VIEWSTATE (ViewState): 

__VIEWSTATE (ViewState) Stores data across calls to the server Holds Primitive types Strings HashTables ArrayLists

Post Back: 

First Request for myPage User fills in form and submits data Http “Get” myPage.aspx ( no data ) Response = myPage.aspx Browser Http “Post” myPage.aspx ( data ) IsPostBack = false IsPostBack = true Web Server Response = myPage.aspx Post Back

Responding to Events: 

Responding to Events <html> <head> <title>Hello World Web Page</title> <script runat="server"> sub ShowDateTime(sender as object, e as EventArgs) lblDateTime.Text = DateTime.Now end sub </script> </head> <body> <form id="Form1" method="post" runat="server"> <asp:label id="lblDateTime" runat="server"></asp:label> <asp:button id="btnSelect" Text="Select" Runat="server" OnClick="ShowDateTime"> </asp:button> </form> </body> </html>

Slide11: 

optional code-behind Base.vb myPage.aspx Request from Browser execute .dll * generate .vb class file * Aspx Engine parse myPage.aspx Language Compiler create .dll file * Yes No Response to Browser optional compiled code-behind pages myProject.dll * Files created within the following folder structure: %SystemRoot%\Microsoft.NET\Framework\version\Temporary ASP.NET Files\ .aspx file changed? No Yes compiled?

Slide12: 

Code-Behind Page: myPage.aspx.vb … Public Class myPage … Protected WithEvents btnSelect As System.Web.UI.WebControls.Button Protected WithEvents txtName as System.Web.UI.WebControls.TextBox … Web Form Page: myPage.aspx <% Page language="vb" Codebehind="myPage.aspx.vb" Inherits="ch3.myPage" %> … <asp:Button id="txtName" Text="MyName" /> <asp:Button id="btnSelect" Text="Select" /> …

Slide13: 

Class Selection Event Method Selection

Page Layout: 

Page Layout Grid Layout Drag and drop controls anywhere Great for fixed size page Flow Layout Similar to traditional ASP Requires tables / nested tables for layout Can also have advantages

Lab – Creating a Web Form: 

Lab – Creating a Web Form