Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET.

Similar presentations


Presentation on theme: "Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET."— Presentation transcript:

1 Web Application Development Introduction

2 Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET

3 What Is a Web Form?.aspx extension Page attributes @ Page directive Body attributes Form attributes

4 Creating a Web Form with Visual Studio.NET New ASP.NET Web Applications create a default Web Form: WebForm1.aspx Create additional Web Forms from the Solution Explorer

5 Lesson: Using Server Controls What is a Server Control? Types of Server Controls Saving View State Demonstration: Converting HTML Controls to Server Controls HTML Server Controls Web Server Controls Practice: Identifying the HTML Generated by Web Server Controls Selecting the Appropriate Control Demonstration: Adding Server Controls to a Web Form

6 What is a Server Control? Runat="server" Events happen on the server View state saved Have built-in functionality 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"/>

7 Types of Server Controls HTML server controls Web server controls Intrinsic controls Validation controls Rich controls List-bound controls Internet Explorer Web controls

8 Saving View State Hidden ViewState control of name-value pairs stored in the Web Form On by default, adjustable at Web Form and control level

9 HTML Server Controls Based on HTML elements Exist within the System.Web.UI.HtmlControls namespace

10 Web Server Controls Exist within 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 id="TextBox1" runat="server">Text_to_Display <input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/> <input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/>

11 You need specific functionality such as a calendar or ad rotator The control will interact with client and server script You are writing a page that might be used by a variety of browsers You are working with existing HTML pages and want to quickly add ASP.NET Web page functionality You prefer a Visual Basic-like programming model You prefer an HTML-like object model Use Web Server Controls if: Use HTML Server Controls if: Bandwidth is not a problemBandwidth is limited Selecting the Appropriate Control

12 Lesson: Using Code-Behind Pages How to Implement Code What are Code-Behind Pages?

13 How to Implement Code Three methods for adding code: Put code in the same file as content (mixed) Put code in a separate section of the content file (inline code) Put code in a separate file (code-behind pages) Code-behind pages are the Visual Studio.NET default

14 What are Code-Behind Pages? Separation of code from content Developers and UI designers can work independently Form1.aspxForm1.aspx Form1.aspx.vb Form1.aspx.vb or Form1.aspx.cs code code Separate filesSingle file

15 Lesson: Adding Event Procedures to Web Server Controls What are Event Procedures? Client-Side Event Procedures Server-Side Event Procedures Creating Event Procedures Interacting with Controls in Event Procedures

16 What are Event Procedures? Action in response to a user’s interaction with the controls on the page

17 Client-Side Event Procedures Internet.HTM Pages Typically, used only with HTML controls only Interpreted by the browser and run on the client Does not have access to server resources Uses

18 Server-Side Event Procedures Used with both Web and HTML server controls Code is compiled and run on the server Have access to server resources Use or Internet.ASPX Pages

19 Creating Event Procedures Visual Studio.NET declares variables and creates an event procedure template Using the Handles keyword adds many event procedures to one event protected System.Web.UI.WebControls.Button cmd1; private void InitializeComponent() { this.cmd1.Click += new System.EventHandler(this.cmd1_Click); this.Load += new System.EventHandler(this.Page_Load); } private void cmd1_Click(object s, System.EventArgs e) protected System.Web.UI.WebControls.Button cmd1; private void InitializeComponent() { this.cmd1.Click += new System.EventHandler(this.cmd1_Click); this.Load += new System.EventHandler(this.Page_Load); } private void cmd1_Click(object s, System.EventArgs e) Protected WithEvents cmd1 As System.Web.UI.WebControls.Button Private Sub cmd1_Click(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles cmd1.Click Protected WithEvents cmd1 As System.Web.UI.WebControls.Button Private Sub cmd1_Click(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles cmd1.Click

20 Interacting with Controls in Event Procedures Read the properties of Web server controls Output responses to other Web server controls lblGreeting.Text = "new text" strGreeting = "Hello " & txtName.Text strGreeting = "Hello " + txtName.Text; lblGreeting.Text = "new text";

21 Lesson: Using Page Events Understanding the Page Event Life Cycle Handling Page.IsPostback Events

22 Understanding the Page Event Life Cycle Page_Load Page_Unload Textbox1_Changed Button1_Click Page is disposed Page_Init Control events Change Events Action Events

23 Handling Page.IsPostback Events Page_Load fires on every request Use Page.IsPostBack to execute conditional logic Page.IsPostBack prevents reloading for each postback Private Sub Page_Load(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then 'executes only on initial page load End If 'this code executes on every request End Sub Private Sub Page_Load(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then 'executes only on initial page load End If 'this code executes on every request End Sub private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // executes only on initial page load } //this code executes on every request } private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // executes only on initial page load } //this code executes on every request }

24 Lesson: Overview of Using XML Web Services What is an XML Web Service? Why use XML Web Services? Finding an XML Web Service

25 What is an XML Web Service? Programmable logic accessible by standard Web protocols Allows applications to send and receive information across the Internet Language, protocol, and platform independent Stateless architecture Can be asynchronous Based on an evolving W3C standard

26 Why Use XML Web Services? Internet Weather XML Web Service Exchange Rate XML Web Service Exchange Rate XML Web Service Pick your destination: The weather Forecast calls for: The exchange rate is: We can fly you there for only: Rain Redmond $1.56 $1,999.98 Airfare Database Airfare Database Airfare XML Web Service Airfare XML Web Service Northwind Traders Travel Site

27 Publish XML Web service URL and description Finding an XML Web Service.disco.wsdl Web Service Proxy Web Form UDDI 11 22 33 44 5566 11 22 33 44 55 Discover XML Web service Locate XML Web service URL Read.wsdl description Bind XML Web Service to Proxy Call XML Web Service from the Web Form by Proxy 66

28 Lesson: Using a Proxy to Call an XML Web Service Using Proxies to Call XML Web Services How to Use a Proxy to Call an XML Web Service XML Web Service Error Handling

29 Using Proxies to Call XML Web Services Appear the same as the original class, but do not contain application logic Use SOAP to interact with the XML Web Service Created from the ServiceName.asmx.wsdl file Add members to manage interactions with the XML Web service and support asynchronous calls Internet XML Web Service Proxy Web Form SOAP

30 How to Use a Proxy to Call an XML Web Service 1.Create a Web reference for the XML Web Service 2.Create an instance of the XML Web Service 3.Call the Web methods of the XML Web Service 4.Build the ASP.NET Web Application Sub Button1_Click(s As Object, e As EventArgs)... Dim ProxyGetStocks As New _ GetStocks.localhost.Service1() lblResults.Text = _ ProxyGetStocks.GetRating("Contoso") End Sub Sub Button1_Click(s As Object, e As EventArgs)... Dim ProxyGetStocks As New _ GetStocks.localhost.Service1() lblResults.Text = _ ProxyGetStocks.GetRating("Contoso") End Sub 11 22 33 44 C# Code Example

31 XML Web Service Error Handling Service unavailable SOAP exceptions from XML Web Services GetStocks.StockWebRef.Service1 ProxyGetStocks = new GetStocks.StockWebRef.Service1(); ProxyGetStocks.Timeout = 10000; try { lblMessage.Text = ProxyGetStocks.GetRating(TextBox1.Text); } catch (Exception err) { lblMessage.Text = err.Message; } GetStocks.StockWebRef.Service1 ProxyGetStocks = new GetStocks.StockWebRef.Service1(); ProxyGetStocks.Timeout = 10000; try { lblMessage.Text = ProxyGetStocks.GetRating(TextBox1.Text); } catch (Exception err) { lblMessage.Text = err.Message; } Visual Basic.NET Code Example

32 Lesson: Creating an XML Web Service How to Create an XML Web Service XML Web Service Code Instructor-Led Practice: Creating an XML Web Service

33 How to Create an XML Web Service 1.Create a new XML Web Service project in Visual Studio.NET 2.Declare the WebMethod functions 3.Build the XML Web Service project 4.Test with a browser 11 22 33 44

34 XML Web Service Code.asmx page.asmx.vb page Imports System Imports System.Web.Services Class Service1 Public Function function1() As type 'function_here End Function End Class Imports System Imports System.Web.Services Class Service1 Public Function function1() As type 'function_here End Function End Class C# Code Example

35 Lesson: Configuring an ASP.NET Web Application Overview of Configuration Methods Configuring a Web Server Using Machine.config Configuring an Application Using Web.config Understanding Configuration Inheritance Storing and Retrieving Data in Web.config Using Dynamic Properties

36 Overview of Configuration Methods Machine.config file Machine-level settings Web.config files Application and directory-level settings Both Machine.config and Web.config files are: Well-formed XML camelCase Extendable

37 Configuring a Web Server Using Machine.config Settings in the Machine.config file affect all Web applications on the server Only one Machine.config file per Web server Most settings can be overridden at the application level using Web.config files

38 Configuring an Application Using Web.config One or more Web.config files per Web application All configuration information for the application is contained in the Web.config files Contains a section for each major category of ASP.NET functionality Security Mode General application settings Tracing

39 Understanding Configuration Inheritance Application-level Web.config file inherits settings from Machine.config file Settings in Web.config file that conflict override inherited settings Individual directories may have Web.config files that inherit from— and can override— application-level settings Machine.config Web.config CONFIG VirtualDir SubDir

40 Storing and Retrieving Data in Web.config Storing application settings in a Web.config file Retrieving application settings from a Web.config file <add key="pubs" value="server=localhost; integrated security=true; database=pubs"/> <add key="pubs" value="server=localhost; integrated security=true; database=pubs"/> Dim strPubs As String = _ ConfigurationSettings.AppSettings("pubs") Dim strPubs As String = _ ConfigurationSettings.AppSettings("pubs") AppSettingsReader App = new AppSettingsReader(); string strPubs = (string)App.GetValue("pubs", typeof(string)); AppSettingsReader App = new AppSettingsReader(); string strPubs = (string)App.GetValue("pubs", typeof(string));

41 Using Dynamic Properties Store property values in Web.config files rather than in the application's compiled code Allows easy updates without recompiling the application Enable and configure through object properties

42 Lesson: Deploying an ASP.NET Web Application Web Application Deployment Preparing a Web Application for Deployment Practice: Selecting Necessary Files Sharing Assemblies in the Global Assembly Cache Updating Your Web Application

43 Web Application Deployment Copy files locally or FTP files remotely Configure the target folder as a virtual directory in IIS Copy all necessary files, including the \bin directory and content No need to register components

44 Preparing a Web Application for Deployment 1.Build the Web application 2.Do not select unnecessary files Visual Studio.NET solution files (.vbproj,.vbproj.webinfo,.csproj,.csproj.webinfo, etc.) Resource (.resx) files Code-behind pages (.vb,.cs) 3.Copy or FTP necessary files to the production directory

45 Sharing Assemblies in the Global Assembly Cache The global assembly cache provides storage for assemblies you need to share Machine-wide cache for code Because DLL files are not registered, they are not easily shared between Web applications

46 Updating Your Web Application Copy or FTP files to update the Web application Do not need to stop and restart IIS.dll files can be updated while the site is still running

47 Questions?


Download ppt "Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET."

Similar presentations


Ads by Google