1 / 199

Dr. Minder Chen Associate Professor and Area Coordinator of Decision Science and MIS George Mason University Email: m

MIS 412: E-Business Systems Development Fall 2006. Using ASP.NET. Dr. Minder Chen Associate Professor and Area Coordinator of Decision Science and MIS George Mason University Email: mchen@gmu.edu 703-993-1788. Fall 2006. ASP.NET. Teaching Materials & Resources

quynh
Download Presentation

Dr. Minder Chen Associate Professor and Area Coordinator of Decision Science and MIS George Mason University Email: m

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIS 412: E-Business Systems Development Fall 2006 Using ASP.NET Dr. Minder Chen Associate Professor and Area Coordinator of Decision Science and MIS George Mason University Email: mchen@gmu.edu 703-993-1788 Fall 2006

  2. ASP.NET • Teaching Materials & Resources • Visual Web Developer Express as a Web Development Tool • HTML Form Data Handling: The Traditional Approach • Event-Driven Programming Model: Web Server Controls and Post-back • State Management: Session, Cookie, etc. • Basic Web Database Programming Using ADO.NET • New Features in ASP.NET 2.0 • ASP.NET 2.0 Style Database Programming: Data Source Controls and New Data-Bound Controls (GridView, DetailsView, FormView) • Master Page, Navigation, Theme, & UI Tips • A Simple Shopping Cart Example

  3. Resources • Web site: • My ASP.NET course Web site: http://gunston.gmu.edu/ecommerce/ebiz/ • Microsoft official site: http://www.asp.net • Tutorial: http://www.asp.net/QuickStart/aspnet/Default.aspx • http://msdn.microsoft.com/asp.net/community/authors/stephenwalther/default.aspx by Stephen Walther • Download Visual Web Developer • http://msdn.microsoft.com/vstudio/express/vwd/default.aspx • Books • Murach's ASP.NET 2.0 Web Programming with VB 2005 (Paperback) by Anne Boehm, Doug Lowe, 2006. (text book) • Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, and Chris Ullman (Paperback - Nov 10, 2005) • Murach's ASP.NET Web Programming with VB.NET (Paperback), by Doug Lowe, Anne Prince, 2003. • ASP.NET 2.0 Unleashed (Paperback) by Stephen Walther

  4. .NET Framework VB.NET C++ C# JScript J# Visual Web Developer Visual Studio .NET Common Language Specification ASP.NET Web FormsWeb Services Mobile Forms Windows Forms ADO.NET and XML Base Class Library Common Language Runtime Operating System

  5. Visual Web Developer Express as a Web Development Tool • Visual Studio .NET 2002 • Visual Studio .NET 2003 • Web Matrix • Visual Web Developer • Visual Studio .NET 2005 • Additional software products • SQL Server Express 2005 • SQL Server 2005 • Access • Deployment • Windows server 2003 running IIS • .NET Framework SDK

  6. Form Handling: No Web Server Control <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" > Enter your name: <input id="Text1" name="username" type="text" /> <input id="Submit1" type="submit" value="submit" /> <% Response.Write("Hello <b>" & _ Request.Params.Get("username") & "</b>")%> </form> </body> </html> Submit to the form itself (Postback) since there is no action attribute Mixing HTML and Server side scripting code

  7. Form Processing

  8. Registration.htm <html> <head> </head> <body> <h1>Registration Form </h1> <form action="registration.aspx" method="post"> Name: <input type="text" name="username" /> <p> Password: <input type="password" name="psw" /> </p> <p> <input type="checkbox" name="programming" />&nbsp;Have programming experience </p> <fieldset style="WIDTH: 646px; HEIGHT: 91px"> <legend title="Test">Choose Favorite Color</legend> <input type="radio" value="1" name="color" />Red<br /> <input type="radio" value="2" name="color" />Green<br /> <input type="radio" value="3" name="color" />Blue </fieldset>

  9. Continued… <p> Select all your skills: </p> <select title="Use CTL key to select more than one item" style="HEIGHT: 54px" multiple="multiple" size="3" name="skills"> <option value="db" selected="selected">Database</option> <option value="wp">Web programming</option> <option value="sa">Analysis and design</option> <option value="ec">Electronic Commerce</option> </select> <p> Your comment: <br /> </p> <textarea name="comment" rows="5" cols="44"></textarea> <p> <input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Reset" /> </p> </form> </body> </html>

  10. Registration.aspx <%@ Page Language="VB" %> <script runat="server"> Public Enum Colors Red = 1 Blue = 2 Green = 3 End Enum Sub Page_Load() If Request.Params.Get("UserName").Trim() <> Request.Params.Get("PSW").Trim() Then LabelMsg.Text = "Your user name and password do not match. Please go back to " & _ "previous page. <input type=button value='Go Back' onClick='history.back();'>" Exit Sub End If Panel1.Visible = True LabelName.Text = Request.Params.Get("UserName") Dim prog as String prog = Request.Params.Get("programming") If prog = "on" Then LabelProgramming.Text = "Yes" Else LabelProgramming.Text = "No" End If

  11. Continued… Dim skillset as String() Dim skill as String skillset = Request.Params.GetValues("skills") If skillset is Nothing Then LabelSkill.Text = "You do not have any skill!" Else For each skill in skillset LabelSkill.Text &= skill & "<br>" Next End if Dim UserComment as String UserComment = Request.Params.Get("comment") LabelComment.Text = replace(UserComment, Microsoft.VisualBasic.ControlChars.CrLf, "<br>") Dim myColor as Integer ' LabelColor.Text = Request.Params.Get("color") myColor = CType(Request.Params.Get("color"), Integer) Select Case myColor Case Colors.Red LabelColor.Text = Colors.Red.ToString() Case Colors.Blue LabelColor.Text = Colors.Blue.ToString() Case Colors.Green LabelColor.Text = Colors.Green.ToString() End Select End Sub </script>

  12. Continued… <html><head></head><body> <form id="Form1" runat="server"> <h1>Submission Confirmation </h1> <p> <asp:Label id="LabelMsg" runat="server"></asp:Label> </p> <asp:Panel id="Panel1" runat="server" Visible="False"> Your name is: <asp:Label id="LabelName" runat="server"></asp:Label> <p> You like programming: <asp:Label id="LabelProgramming" runat="server"></asp:Label> </p> <p> Your skills include: <br /> <asp:Label id="LabelSkill" runat="server"></asp:Label> </p> <p> The color your like is: <br /> <asp:Label id="LabelColor" runat="server"></asp:Label> </p> <p> Your comment is: </p> <p> <asp:Label id="LabelComment" runat="server"></asp:Label> </p> </asp:Panel> </form></body></html>

  13. Navigating Between Web Pages • Hypertext links with QueryString (URL variables) • Form submission • Request.Redirect() • Server.Transfer() -- Doesn't work! • Server.Execute() -- Rarely used! • Windows.Open() -- Client-side JavaScript!

  14. Hypertext Links and Forms • Hypertext link • <a href="URL?x=3&y=Hello">Next</a> • Standard HTML Forms <form action="URL" method="post"> Form elements </form> QueryString Post: Send form data as standard input Get: Send form data as QueryString • URL of the form handling page. • In ASP.NET, when you use Web form contriols, the action is to submit to the form itself, i.e., PostBack

  15. Request.Params • Gets a combined collection of QueryString, Form, ServerVariables, and Cookies items. • Request.Params.Get("name") • Gets the values of a specified entry in the NameValueCollection combined into one comma-separated list. • A String is return. • Request.Params.GetValues("name") • Gets the values of a specified entry in the NameValueCollection. • An array of String is returned.

  16. Create a New Web Site

  17. Creating a New Page

  18. Select a Web Form

  19. Toolbox – Web Server Controls

  20. Properties Window

  21. Create an Event Procedure • Double click on a Web Server Control • Determine the event to be associated with the control • Write appropriate code for responding to the event

  22. Set a Breakpoint for Debugging • Click on the sideline of the corresponding code line to set the breakpoint • Click again to remove the breakpoint

  23. Set as Start Page • Your project/web site may contain many Web forms. • When you try to run and test a specific Web page, you should set that page to be the Start page. • Right mouse button click on the page, choose "Set As Start Page" from the pop-up menu

  24. Running and Debugging your Web Form

  25. Web.config file • You need to Add a new Web.config file for the whole Web site / Web application

  26. Web.config

  27. Web Application Administration • Hand editing this file or use the web admin tool to configure settings for your application. Usethe Website->Asp.Net Configuration option in VWD • A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config

  28. Running the Web page

  29. Debugging Functions

  30. Error List • If you double click on a Web server control, an event procedure for the control will be created. When you use the single file format, then if you delete the procedure without deleting the reference to it in the Web server control (such as OnTextChanged="TextBox1_TextChanged"attribute below), an error will occur during compilation. If you use code behind, this will not be a problem. Enter Your Name: <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"> </asp:TextBox> Just say NO! Include all errors from Web forms in the Web site

  31. Add Watch • Highlight a variable, an object, or a property • Right mouse button click to select the "Add Watch" from the menu Click here if you are looping through this variable the second time during debugging to update the current value.

  32. Page Load Event • Page Load event will be executed every time you access the page. • Web server controls' events always post back to the page itself. • Use IsPostBack function to determine whether it is the first request of the page or a post back to the page. Postback ASP.NET page's <form runat="server"> tag does not have the action attribute, therefore all Web server controls event will send the form variables (i.e., Web server controls' data) to the same page to be processed by corresponding server-side event-handling methods.

  33. PostBack <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If IsPostBack Then LabelWelcome.Text = "Thank you, " & TextBox1.Text & _ " for using Hello World!" Else LabelWelcome.Text = "Welcome to my Hello World!" End If End Sub Protected Sub Button1_Click(…..) Label1.Text = "Hello " & TextBox1.Text End Sub </script>

  34. Page/Control Event Execution PostBack First Request For a particular user visits an ASP.NET page Page DLL is loaded, control hierarchy initialized They may be triggered on PostBack Page_Load Textbox1_Changed 1. Change Events Button1_Click 2. Action Events Control hierarchy (Dynamically generated HTML page) is rendered Page_PreRender Page_Unload Page is disposed

  35. ASP.NET Pages: Part Declarative, Part Code • Combines declarative tags (HTML, ASPX directives, server controls tags, and static text) with code in a single file or in separate files. • Unlike ASP, good separation provided between code and tags. • VWD and VS 2005 support intelli-sense and debugging with single-file format.  single file separate files (“code-behind”) code code <tags> <tags> Form1.aspx Form1.aspx Form1.aspx.vb

  36. Control Event Processing • Events are: • Triggered on the client by the user • Handled in server code • Requires a postback to the same page • ViewState of controls saves page and control properties between round trips, therefore helps restore control to its previous state. • Implemented as a hidden form field • Disable via setting the EnableViewState attribute • EnableViewState=false • Data Binding resets control state

  37. ViewState and PostBack First Request Response __VIEWSTATE = "dDwt…" <Input id="TextBox1"> Post back to the same page __VIEWSTATE = "dDwt…" Textbox1.Text = "Minder Chen" Response Default value __VIEWSTATE = "dDwt…" <Input id="TextBox1" value="Minder Chen" …> Hello2.aspx.vb If Not IsPostBack … Hello2.aspx <asp:textbox id="TextBox1" runat="server" /> Minder Chen States of a page is maintained via the ViewState between the Postback

  38. Web Form Design/Development Process • Paint/design Web form • What Web server controls to use • Set their some of their properties to certain values • Define the dynamic behaviors of the Web form • Determine what events associated with these controls need to be written • Click event of the Button1 • Write the code to to handle the click event of Button1, i.e., Button1_click() • Test the Web form

  39. RadioButtonList.aspx runtime

  40. Web Form Designer Checkbox with AutoPostBack RadioButtonList Panel Visible = False

  41. Set Up Properties of Web Server Controls

  42. Define Items in RadioButtonList control

  43. RadioButtonList.aspx <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) If CheckBox1.Checked Then Label1.Text = "You know ASP.NET 2.0 <br>" Label1.Text &= "Your level of expertise is: " & RadioButtonList1.SelectedItem.Text _ & "<br>" Label1.Text &= "Your level of expertise code is: " & RadioButtonList1.SelectedValue Else Label1.Text = "You don't know ASP.NET 2.0 <br>" End If End Sub Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) If CheckBox1.Checked Then Panel1.Visible = True Else Panel1.Visible = False End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs) Label1.Text = "" ' Reset error message End Sub </script> Panel1.Visible = Not Panel1.Visible

  44. Code -- Continued <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>RadioButtonList </title> </head><body> <form id="form1" runat="server"> <div> <strong><span style="font-size: 14pt">Auto Postback + Checkbox + DadioButtonList&nbsp;<br /> <br /> <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="I know ASP.NET 2.0" OnCheckedChanged="CheckBox1_CheckedChanged" /><br /> <br /> </span></strong> <asp:Panel ID="Panel1" runat="server" BorderStyle="Outset" Height="136px" Visible="False"Width="256px"> <strong>Choose your level of expertise in ASP.NET 2.0 </strong> <br /> <asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Bold="True" > <asp:ListItem Selected="True" Value="1">Basic</asp:ListItem> <asp:ListItem Value="2">Intermediate</asp:ListItem> <asp:ListItem Value="3">Advanced</asp:ListItem> </asp:RadioButtonList> </asp:Panel> </div><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /><br /><br /> <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label> </form> </body></html>

  45. Runtime Compilation Code-behindclass Parse Generate ASPX Engine Page Class Generate PageClass Subsequent Requests Instantiate Compile Response Response Instantiate, Process and Render First Request after the deployment ASPX File

  46. Major Build-in ASPX Objects • Request Object • Cookies • Form • QueryString • ServerVariables • ClientCertificate • Response Object • Cookies • (Properties) • (Methods) S e r v e r C l i e n t • Server Object • (Properties) • (Methods) Application Object Session Object Cache Object

  47. ASP Application and Session Objects I I S ASP.NET Application Object 1 Application Object 2 Application Object 3 Session Object 1 Session Object 1 Session Object 1 Session Object 2 Session Object 2 Session Object 2 Session Object 3 Session Object 3 Session Object 3

More Related