Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computing with C# and the .NET Framework

Similar presentations


Presentation on theme: "Computing with C# and the .NET Framework"— Presentation transcript:

1 Computing with C# and the .NET Framework
Chapter 16 ASP.NET

2 HTML HTML (Hypertext Markup Language)
Adds tags to specify formatting of web pages Tags use angle brackets Some like <br> require no text information Others like <h1> indicate a size for text included up to the </h1> tag <h1> is a start tag </h1> is an end tag

3 New paragraph (after a blank line). <em> ... </em>
<br> Break to the next line. <p> New paragraph (after a blank line). <em> ... </em> Emphasize the text. <strong>...</strong> Strongly emphasize the text. <title>... </title> Title, displayed separately from text. <h1>... </h1> Top-level header. <h3>... </h3> Third-level header., (lowest is sixth). <u1> ... </u1> An unordered list. <1i> Element of a list. <a>... </a> An anchor, a hypertext link. <img> An image. <form>…</form> Contains controls Figure 16.1 Some HTML tags

4 Web Server Controls Add user interface controls to a web page
Run on server Textbox, for example <asp:textbox id="Order" Columns="20" runat="server" /> To handle events, either add code to the web page or use a separate code behind C# program

5 Adding script code A button web control
<asp:button id="submit" Text="Submit" runat="server“ onclick="Submit_Click" /> onclick attribute indicate event handler Script adds C# code to web page to handle click <script language="c#" runat="server"> public void Submit_Click(Object Sender, EventArgs e) {output.Text= "You ordered " + Order.Text;} </script>

6 Using code behind Page directive name source file and class name
Page Src="GetOrderBehind.aspx.cs" Inherits="GetOrderBehind"%> No longer use onclick attribute <asp:button id="submit" Text="Submit" runat="server" />

7 Code behind GetOrderBehind.aspx.cs
protected Button submit; // declare control private void Page_Init() { submit.Click += new EventHandler(Submit_Click); } // register event handler public void Submit_Click(Object Sender, EventArgs e) {output.Text= "You ordered " + Order.Text;} // implement event handler

8 Deploying a web page Use Internet Information Server (IIS) available on Windows 2000, Windows XP and various hosting sites. Create a virtual directory linked with the folder containing your code. (ch16 used here) Web page uses .aspx extension Enter URL in browser. If IIS on local machine

9 GET and POST Using get in the form tag sends an HTTP GET request, with data appended to the URL <form method="get" runat="server"> Using post sends an HTTP POST request with data sent after the request headers <form method="post" runat="server">

10 Three-tiered architectures
Client -- front tier, user interface Servlet – middle tier, implements business logic Database – back tier, contains persistent data Client sends data to server Server queries database Server returns response to client

11 Session Tracking HTTP is stateless, and does not save information about the client Session property holds HttpSessionState to keep data between connections Store an ArrayList in the Session to hold user’s order, which is updated at each connection by that user. A new user has a different Session


Download ppt "Computing with C# and the .NET Framework"

Similar presentations


Ads by Google