1 / 39

ASP.Net Web Applications

ASP.Net Web Applications. Characteristics of a typical data driven web application. Web Server. HTTP Request. ASP / JSP ISAPI / NSAPI …… /……. HTTP Response. ADO / JDBC. HTML Graphics Active-X Java Applets. Database Server. Building dynamic web application. Working with ASP.NET.

liko
Télécharger la présentation

ASP.Net Web Applications

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. ASP.Net Web Applications

  2. Characteristics of a typical data driven web application Web Server HTTP Request ASP / JSPISAPI / NSAPI…… /…… HTTP Response ADO / JDBC HTML GraphicsActive-XJava Applets DatabaseServer

  3. Building dynamic web application • Working with ASP.NET. • Using Web Controls • Looking behind “The ViewState hidden field” • Using Page.IsPostBack • Using Microsoft ADO.NET to Access Data • Creating a Microsoft ASP.NET Web Application

  4. Working with ASP.NET • Introducing ASP.NET • Creating Web Forms • Adding ASP.NET Code to a Page • Handling Page Events

  5. Introducing ASP.NET ASP.NET Web Server Browser Web Forms Web.config Page1.aspx Code-behind pages Output Cache Internet Page2.aspx machine.config global.asax Database Components XML Data

  6. ASP.Net Execution Model

  7. Creating Web Forms 1/3 Web Matrix

  8. Creating Web Forms 2/3 Visual Studio .Net

  9. Creating Web Forms 3/3 ASP.Net Whidbey IntelliSense Everywhere Asp.Net Whodgey is the Microsoft next generation development tool for Asp.Net Web Applications. It is an improved mixture of Web Matrix and Visual Studio.Net.

  10. Adding ASP.NET Code to a Page 1/2

  11. Adding ASP.NET Code to a Page 2/2 <%@ Page Language="C#" %> <html> <head> </head> <body> <form runat="server"> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button> <asp:Label id="Label1" runat="server" >Label</asp:Label> <asp:TextBox id="TextBox1" runat="server"></asp:TextBox> <input type=“text” name=“TextBox12”> <%Response.Write (“shalom”)%> </form> </body> </html>

  12. Handling Page Events <%@ Page Language="C#" %> <script runat="server"> void Button1_Click(object sender, EventArgs e) { Label1.Text = TextBox1.Text; } </script> <html> <head> </head> <body> <form runat="server"> <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button> Dubble Click on Buttone1

  13. Using Web Controls • What Are Web Controls? • Using Intrinsic Controls • Using Input Validation Controls • Selecting Controls for Applications • Demo

  14. What Are Server Controls? • Runat="server" • Events happen on the server • ViewState 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"/>

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

  16. HTML Server Controls • Based on HTML elements • Exist within the System.Web.UI.HtmlControls namespace <input type="text" id="txtName" runat="server" />

  17. Web Server Controls • Exist within theSystem.Web.UI.WebControls namespace Control syntax HTML generated by control <asp:TextBox id="TextBox1" runat="server">Text_to_Display </asp:TextBox> <input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/>

  18. What Is Input Validation? • Verifies that a control value is correctly entered by the user • Blocks the processing of a page until all controls are valid • Avoids spoofing,or the addition ofmalicious code

  19. Client-Side and Server-Side Validation • ASP.NET can create both client-side and server-side validation • Client-side validation • Dependent on browser version • Instant feedback • Reduces postback cycles • Server-side validation • Repeats all client-side validation • Can validate against stored data User Enters Data Error Message Valid? No Client Yes Server Valid? No Yes Web ApplicationProcessed

  20. ASP.NET Validation Controls ASP.NET provides validation controls to: • Compare values • Compare to a custom formula • Compare to a range • Compare to a regular expression pattern • Require a user input • Summarize the validation controls on a page

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

  22. Looking under the hood “The ViewState hidden field” • Hidden ViewState control of name-value pairs stored in the Web Form • On by default, adjustable at Web Form and control level <%@ Page EnableViewState="False" %> <asp:List id="ListName" EnableViewState="true" runat="server"> <input type="hidden" name="__VIEWSTATE" value="dDwtMTA4MzE0MjEwNTs7Pg==" />

  23. Looking under the hood “The ViewState hidden field” 1/3 • Understanding ViewState via a demo : • Add the following Web Controls a Form • ASP:Text • ASP:Lable • ASP:Button • Double click the Text Box to generate the TextBox1_OnChange Event Code. • Inside the event code write the following code: Label1.Text = System.DateTime.Now.ToLongTimeString();

  24. Looking under the hood “The ViewState hidden field” 2/3 The value of TextBox1, “yosef” is being html delivered to the browser in two places. First place in <Input name=“TextBox1” type=“text”> This value can be changed by the user Second place within the VIEWSTATE hidden field. This value can not be changed. When the html form is being submitted the server automatically response to changes in TextBox1and generate server event.

  25. Looking under the hood “The ViewState hidden field” 3/3 <%@ Page Trace="true" Language="C#" %>

  26. Using Page.IsPostBack

  27. Using Microsoft ADO.NET to Access Data • Displaying Data in the DataGrid Control • Using Templates • Using the Repeater Control • Using Datasets vs. DataReaders

  28. Displaying Data in the DataGrid Control 1. Build a Connected/Disconnected Data Source 2. Bind the Data Grid to your Data Source DataGrid1.DataSource = reader1; Or DataGrid1.DataSource = DataSet1.Tables[0].DefaultView; 3. Tell The Control to generate HTML Datagrid1.DataBind();

  29. The DataAdapter Object Model DataSet DataAdapter SelectCommand UpdateCommand InsertCommand DeleteCommand DataReader Command Command Command Command Connection sp_SELECT sp_UPDATE sp_INSERT sp_DELETE Database

  30. Generating a Dataset • You can generate a dataset… • …through the UI… • Creates a dataset that allows you to access data as an object • …or through code… • …and then fill the DataSet from the DataAdapter(s) DataSet ds = New DataSet() DataAdapter1.Fill(ds) DataAdapter2.Fill(ds)

  31. Property Description DataSource • The DataSet containing the data DataMember • The DataTable in the DataSet DataTextField • The field in the DataTable that is displayed DataValueField • The field in the DataTable that becomes the value of the selected item in the list Displaying DataSet Data in List-Bound Controls • Set the properties • Fill the DataSet, then call the DataBind method DataAdapter1.Fill(ds) lstEmployees.DataBind()

  32. Updating Data 1/3 Using the DataGrid property builder add the Edit, Update, Cencle Buttons/Links

  33. Updating Data 2/3 Click on the Events button (mark with red circle) and duble click inside the Cancel Command. You will see DataGrid1_CancelCommand.Do the same for EditCommand and UpdateCommand void DataGrid1_CancelCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_EditCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e) { }

  34. Updating Data 3/3 Click on the Events button (mark with red circle) and duble click inside the Cancel Command. You will see DataGrid1_CancelCommand.Do the same for EditCommand and UpdateCommand void DataGrid1_CancelCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_EditCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e) { }

  35. Updating Data 4/3 Click on the Events button (mark with red circle) and duble click inside the Cancel Command. You will see DataGrid1_CancelCommand.Do the same for EditCommand and UpdateCommand void DataGrid1_CancelCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_EditCommand(object sender, DataGridCommandEventArgs e) { } void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e) { }

  36. Using Datasets vs. DataReaders • Open conversation

  37. Creating a Microsoft ASP.NET Web Application • Requirements of a Web Application • Sharing Information Between Pages • Securing an ASP.NET Application • Page Output Caching • Application Caching • Demo Samples

  38. Project 2 0f 3 • Building Dynamic Web Application

  39. What Next? Web Services

More Related