SlideShare a Scribd company logo
SERVER-SIDE DEVELOPMENT An Introduction  01
Overview Introduces the nature and structure of ASP.NET. Illustrates how to use Microsoft Visual Studio 2005 Tutorial walkthroughs for creating some sample ASP.NET Web forms using Visual Studio.  in-depth coverage of how ASP.NET works is left to the next chapter.
What is server-side development? Refers to software development for applications in which the majority of processing occurs on one or more servers (and not on the client’s machine).
Static vs Dynamic Web Pages Most web pages that you view are not static HTML pages. Instead they are output from programs that run on servers. These programs can interact with server resources like databases and XML Web services.
Static Web Content
Dynamic Web Content
Dynamic Web Technologies There are quite a number of different technologies for dynamically generating Web content on servers.  ASP.NET ASP CGI ColdFusion JSP PHP Ruby on Rails
Dynamic Web Technologies All of these technologies share one thing in common:  Using programming logic, they generate HTML+CSS+Javascript on the server and send it back to the requesting browser.
Dynamic Web Technologies (again)
What is  not  a Dynamic Server Technology Normal Javascript is  not  a dynamic server technology. Javascript is a simple programming language that is executed by the browser, not the server. It is embedded within the HTML that is sent to the browser. It can interact with a server, but it executes  after  the page is received by the browser. <body> <p>Blah blah blah … <script language=&quot;Javascript&quot;> document.write(&quot;This is dynamic client-generated content&quot;); something.InnerHTML = &quot;This is not server-generated&quot;; </script>
What is  not  a Dynamic Server Technology Flash is not a dynamic server technology. Flash refers the Shockwave Flash file (SWF) that is sent to the browser. Your browser, via the Flash Player plug-in, is able to run and display the SWF file. Typically used for advertisement banners, games, or richer user interfaces than are possible with HTML. It can interact with a server, but it executes after the page is received by the browser.
Types of Dynamic Technology There are a quite a number of different technologies for dynamically generating web content on the server. All of these technologies share one thing in common: Using programming logic they generate HTML on the server and send it back to the requesting browser. We could categorize dynamic technology into three different types: Direct Output Page Scripting Hybrid
Direct Output In such a case, programs running on the server directly output HTML back to the client. CGI and Java Servlets are examples. Advantage is fast execution time. Main drawback is that any change in the design of a web page, no matter how minor, requires of intervention of programmer, who must compile the code (and perhaps turn off server to deploy).
Direct Output example public class HelloWorld extends HttpServlet  {  public void doGet(HttpServletRequest request, HttpServletResponse response) {  response.setContentType(&quot;text/html&quot;);  PrintWriter out = response.getWriter();  out.println(&quot;<html>&quot;);  out.println(&quot;<body>&quot;);  out.println(&quot;<head>&quot;);  out.println(&quot;<title>Hello World!</title>&quot;);  out.println(&quot;</head>&quot;);  out.println(&quot;<body>&quot;);  out.println(&quot;<h1>Hello World!</h1>&quot;);  out.println(&quot;</body>&quot;);  out.println(&quot;</html>&quot;); } }
Page Scripting Due to the inefficiencies and difficulties in creating direct output web applications, page scripting dynamic content systems have been developed. That is, scripts embedded within HTML.  HTML for static elements, scripts for dynamic elements. Each page contains the scripts it needs. Examples Microsoft's ASP, Allaire's ColdFusion, PHP. All of these systems using  scripting languages . These languages are interpreted by the server rather than compiled using a compiler. Advantage: rapid development times for developers. Disadvantage: slower execution speed.
Example PHP Script <?php require_once(&quot;utilities/header.php&quot;); ?> <?php $currentTime =  date(&quot;F j, Y, g:i a&quot;); $colors = array('white','black','red','green','blue','yellow','orange'); ?> <html> <head></head> <body> <form> The time is now  <? echo $currentTime; ?>   <br/> Choose a color: <select> <? for ($i=0; $i<count($colors); $i++) { echo '<option>'; echo $colors[$i]; echo '</option>'; } ?> </select> </form> </body> </html>
Page Scripting Page scripting systems such as ASP and PHP are great for rapidly developing simple web sites. They can, however, be harder to use when creating large, complex sites  Be hard to maintain since the code created tends not be object-oriented.
Hybrid More recent technologies such as Microsoft's ASP.NET and Sun's JSP use a hybrid approach and combine the direct output and page scripting models. Disadvantage Hard to learn compared to page scripting Advantage Can use modern software engineering best practices thus making it easier to create large complex sites as well as easier to manage and maintain.
Hybrid <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head runat=&quot;server&quot;><title>Scrolling Grid</title></head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot;> <div> <h1>GridView</h1>   <asp:GridView ID=&quot;grdvSample&quot; runat=&quot;server&quot; DataSourceID=&quot;myAccess&quot; GridLines=&quot;none&quot; Font-Size=&quot;x-small&quot; Font-Names=&quot;tahoma&quot; BorderColor=&quot;black&quot; BorderWidth=&quot;1&quot;> <HeaderStyle ForeColor=&quot;white&quot; BackColor=&quot;brown&quot; Font-Bold=&quot;true&quot; /> <RowStyle BackColor=&quot;palegoldenrod&quot; /> <AlternatingRowStyle BackColor=&quot;beige&quot; /> </asp:GridView> <asp:AccessDataSource ID=&quot;myAccess&quot; runat=&quot;server&quot; DataFile=&quot;~/App_Data/ModernEyeCatalog.mdb&quot; SelectCommand=&quot;Select ArtistId,LastName,FirstName,Nationality,YearOfBirth,YearOfDeath from Artists&quot; /> </div> </form> </body> </html> public class CustomPaging : System.Web.UI.Page { public void SortGrid( Object o, DataGridSortCommandEventArgs e)  { // determine which column is to be sorted string sortField = e.SortExpression; // we must rebind data using the sort field BindData(sortField); } }
New Approaches to Dynamic Technology AJAX Asynchronous Javascript with XML is a new technology that combines dynamic server technology, XML, and Javascript to create web applications that are closer to Windows applications or Flash interfaces in their interactivity abilities. E.g., Google Maps and Google Gmail. Dynamic server technology used to retrieve and generate XML data back to browser. Browser then temporarily stores this XML data and uses Javascript to create richer user interface and retrieve data from XML. If user changes XML data, it can be sent back to server for more processing.
What do you need for server development? Web server hardware A server is a computer that serves information to other computers.  Obviously needs to be powerful enough to handle the requests Web server software Software whose purpose is to deliver web content to HTTP requestors.
Web Server Software Apache Open source, often on Linux/Unix OS IIS Microsoft on Windows
ASP.NET Web Server Options To test or run ASP.NET Web applications, web server software is necessary.  Microsoft’s production web server software is  Internet Information Services  (IIS). In order to run IIS, your computer’s operating system  must  be one of the following: Windows 2000,  Windows XP Professional (not XP Home),  Windows Vista Business or Ultimate (not Vista Home Basic),  Windows Server 2003. Windows Server 2008 Windows 7
Visual Studio File Server One of the advantages of using Visual Studio for ASP.NET development is that your site can be run and tested with or without using IIS.  That is, Visual Studio comes with its own web server software so that you can test execute ASP.NET pages on the same computer. The Visual Studio web server can run locally on all current versions of Windows.  The Visual Studio Web server accepts only localhost requests.  It cannot serve pages to another computer, and is therefore suitable only for testing pages locally.
Web Server Options With Visual Studio, we could say that your computer is a  development server  (available only to yourself).  Alternately, you might upload your work to a  staging server  running IIS for team testing.  Of course, if you want others to see this Web application, it must eventually be uploaded to a  production server  (available to your Web application’s audience).
Web Server Options
What is ASP.NET? ASP.NET 4.0 is the current version of ASP.NET, Microsoft’s powerful technology for creating dynamic Web content.  ASP.NET is one of the key technologies of Microsoft's .NET Framework. It is the successor to Active Server Pages (ASP).
ASP.NET Advantages ASP.NET provides a number of advantages compared to Microsoft’s earlier, &quot;classic&quot; ASP technology.  Better performance More powerful development environment Easier maintenance Smoother deployment and configuration
A Digression That May Be Skipped .NET Framework
The .NET Framework Many of the advantages that ASP.NET provides in comparison to other dynamic Web technologies are a result of its integration into Microsoft’s  .NET Framework .  The .NET Framework is a  development framework  that provides a new programming interface to Windows services and APIs, and integrates a number of technologies that emerged from Microsoft during the late 1990s.  The .NET Framework is also a  software platform  for the running and deployment of Windows-based software systems
Core Features of .NET Language interoperability  Fully object-oriented languages  Common runtime engine shared by all languages  Base class library usable by all languages  Simplified deployment  Better security  Better performance
.NET Framework 3.0 In June 2006, Microsoft combined a number of new Windows development technologies and branded them as the .NET Framework 3.0  This .NET Framework 3.0 includes:  Windows CardSpace,  Windows Communication Foundation (formerly “Indigo”),  Windows Presentation Foundation (formerly “Avalon”),  Windows Workflow Foundation (formerly “WinFx”) .NET Framework 2.0.
.NET Framework 3.5 Released November 2007 Coincided with release of Visual Studio 2008 Added some language features to C# Added LINQ (Language Integrated Query) Added ASP.NET AJAX
.NET Framework 4.0 Released April 2010 Coincided with release of Visual Studio 2010 Added some language features to C# Support for some new .NET languages (IronRuby,IronPython,F#)
.NET Architecture The .NET Framework &quot;sits&quot; on top of the Windows operating system. Consists of the following components: Language compilers Common Language Runtime .NET Framework Base Class Library Source: Lam and Tai,  .NET Framework Essentials, 3 rd  Edition  (O'Reilly, 2003).
.NET Components
Language Compilers .NET languages can  interoperate .  This means that you can use multiple .NET languages within a single .NET application.  The Microsoft provided languages are: Visual Basic.NET (VB.NET), C#, JScript.NET, C++, J++ Other .NET languages are available from third-parties. Nonetheless, most .NET applications are written using a single language Doing so generally makes an application easier to maintain and support in the long run.  Language interoperability is, however, often utilized whenever a .NET application makes use of someone else’s compiled class libraries.
How is language interoperability achieved? All .NET languages must follow the rules in the  Common Language Specification  ( CLS ).  These rules define a subset of common data types and programming constructs that all .NET languages must support. All .NET languages are compiled into a common format.  All code is compiled into  Microsoft Intermediate Language  ( MSIL ), also called Common Intermediate Language (CIL or simply IL), rather than binary.
MSIL MSIL is a CPU-independent virtual machine language analogous to Java’s bytecode.  It consists of CPU-independent instructions for loading/storing information and calling methods.  MSIL is not itself interpreted or executed.  The Common Language Runtime (CLR, covered shortly) converts the MSIL into managed native binary code at runtime using the Just-In-Time compiler as methods are called.
.NET Compilation Process
Assemblies MSIL is physically stored within special containers called  assemblies .  While these assemblies have familiar extensions (e.g., DLL or EXE), they are quite different from traditional Windows DLL or EXE files.
Assemblies A .NET assembly contains  MSIL instructions metadata that includes type definitions,  version information,  external assembly references, and other info. This metadata allows different components, tools, and runtimes to work together.  The CLR uses this metadata for verification, security enforcement, and other tasks. For this reason, .NET assemblies are said to contain  managed code , in that the CLR manages the memory utilization and execution of the code.
Sample MSIL Assembly ... .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 1:0:5000:0 } .assembly hello { .hash algorithm 0x00008004 .ver 0:0:0:0 } .module hello.exe // MVID: {F828835E-3705-4238-BCD7-637ACDD33B78} .class private auto ansi beforefieldinit MainApp extends [mscorlib]System.Object { .method public hidebysig static void Main(  ) cil managed { .entrypoint .maxstack  1 ldstr &quot;C# hello world!&quot; call void [mscorlib]System.Console::WriteLine(string) ret } // End of method MainApp::Main .method public hidebysig specialname rtspecialname  instance void .ctor(  ) cil managed { .maxstack  1 ldarg.0 call instance void [mscorlib]System.Object::.ctor(  ) ret } // End of method MainApp::.ctor } // End of class MainApp If we use the IL disassembler ( ildasm.exe ) to turn a binary assembly  into a text assembly, we will see something similar to the following: Metadata MSIL Module
Common Language Runtime (CLR) The CLR is the execution engine for .NET framework applications. provides a common runtime environment for the execution of code written in any of the .NET languages.  It is a software-only, virtual platform that abstracts functionality from the operating system platform.
CLR Conceptually, the CLR and Java's JVM are similar in that they are both runtime infrastructures that abstract the underlying platform differences. However, while the JVM officially supports only the Java language, the CLR supports multiple languages  The JVM executes bytecode, so it too could, in principle, support languages other than Java. Unlike Java's bytecode, though, .NET's MSIL is never interpreted.  Another conceptual difference is that Java code runs on any platform with a JVM, whereas .NET code runs only on platforms that support the CLR (currently only Windows).
.NET Framework Base Class Library  The .NET Framework base class library (BCL) is a large set of standard classes and other types. This library includes classes for: working with the base types and exceptions,  representing common data structures and collections,  performing data access,  constructing Windows and Web interfaces.
BCL These classes are hierarchically organized into  logical  containers called  namespaces . These namespaces are somewhat analogous to Java packages, except that .NET namespaces, unlike Java packages, are not also  physical  containers. Namespaces prevent name clashes  e.g., two assemblies each with a class named  Image . System.Windows.Forms.Image  vs.  System.Web.UI.Image Recall that compiled .NET code (i.e., MSIL) is physically stored in assemblies. an assembly can contain classes in multiple namespaces, or  classes within a namespace can be physically partitioned across multiple assemblies.
Partial .NET Namespaces
.NET Execution .NET programs written in a CLS-compliant language are compiled by the appropriate language compiler into MSIL. The MSIL is persisted into one or more assemblies.  The CLR is then involved in the execution of the MSIL-based programs. This involves: The CLR will invoke the JIT (Just-In-Time) compiler as needed to convert the MSIL into the appropriate machine code. The CLR will execute the resulting machine code but manage code-level security and garbage collection.
.NET Execution
End of .NET Framework digression Back to ASP.NET
ASP.NET Versions 1.0, 1.1 Introduced web form model used by ASP.NET 2.0 Added new features: themes, master pages, security, data source controls, web parts, navigation, profiles 3.5 Added LINQ and ASP.NET Ajax support 4.0 Standardized XHTML rendering, charting, search-friendly URLS, optional viewstate ASP.NET MVC add-in.
ASP.NET MVC Uses the MVC (Model-View-Controller) pattern Radically different alternative to the web forms model of standard ASP.NET. Doesn’t use web forms, controls, postback, viewstate, sessions, etc.
ASP.NET Web Forms An ASP.NET web application : Consists of any number of web pages, controls, programming classes, web services, and other files Residing within a single web server application directory
ASP.NET Web Forms The principal component of an ASP.NET web application are its web pages. These are text files with an .aspx extension and are called  web forms . Consist of two parts: The declaratively-defined (i.e., by markup/tags) visual elements. The programming logic.
Web Form Programming Logic A web form's programming logic can exist in either: The same file as the visual elements  i.e., the  .aspx  file. This code is contained within a  code-declaration block . In a separate class file. The file is usually called a  code-behind file . By convention, its filename is same as  .aspx  file but with a language extension. HelloWorld.aspx   <- web form HelloWorld.aspx.cs   <- code-behind file
HelloWorld.aspx Example <%@ Page Language=&quot;C#&quot; %> <!DOCTYPE html PUBLIC … > <script runat=&quot;server&quot;> protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.ToShortDateString(); } </script> <html> <head><title>Hello World Embedded</title></head> <body> <form id=&quot;form1&quot;  runat=&quot;server&quot;  > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> Web server control Code declaration block Necessary to make this a web form Page directive
Code Behind Version <%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;  CodeFile=&quot;HelloWorldCodeBehind.aspx.cs&quot;  Inherits=&quot;HelloWorldCodeBehind&quot; %> <!DOCTYPE … > <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; > <head> <title>Hello World Code-</title> </head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot; > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public  partial  class  HelloWorldCodeBehind  :  System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.Date.ToString(); } } Page directive HelloWorldCodeBehind.aspx HelloWorldCodeBehind.aspx.cs
Page Directive The  Page  directive is used to define page-specific instructions used by the ASP.NET environment.  This directive indicates that the programming code in any script blocks will be C#. Directives  are processing instructions for the parser and compiler when they process an ASP.NET page.  Although directives can be located anywhere in an .aspx file, the standard practice is to place them at the beginning of the file.  Directive statements are not case sensitive and quotation marks are not required around the attribute values.  <%@ Page Language=&quot;C#&quot; %>
<form> element All ASP.NET pages  must  contain a  <form>  element that contains this  runat  attribute.  All body content in a Web form should appear within this special  <form>  element.  <form id=&quot;form1&quot; runat=&quot;server&quot; > … </form>
<asp:Label> Web Control In the example’s markup, there is an element named  <asp:Label> .  This is a predefined  ASP.NET Web server control  (covered in more detail later).  The markup for this  Label  control sets its  ID  property to the value  myDate .  The  Label  control must contain the  runat=&quot;server&quot;  attribute. If it does not have it, the ASP.NET environment simply passes on the markup to the browser, where it will be ignored.  <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label>
Programming Logic Code can be contained within: Within code-behind class Within code declaration blocks i.e, within the  <script runat=&quot;server&quot;>  element Within code render blocks within the markup. i.e.,  <% inline code here %> Although the use of code render blocks is familiar to ASP programmers,  their use is very much discouraged in ASP.NET .  In the vast majority of cases, we can replace code render blocks with a combination of server controls and programming within either code declaration blocks or within the page’s code-behind file.
Why use code-behind? The real advantage of separating the code into its own file is that it may lead to more maintainable web forms.  One of the main benefits of ASP.NET is that a page’s programming logic can be  conceptually  separated from the presentation by using a code-behind file a page’s programming logic can also be  physically  separated from the presentation/markup. By placing the programming code into its own file, it is also potentially easier to make use of a division of labor in the creation of the site.  Use whichever model you want However, all the examples in text use code-behind.
Code Behind Version <%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;  CodeFile=&quot;HelloWorldCodeBehind.aspx.cs&quot;  Inherits=&quot;HelloWorldCodeBehind&quot; %> <!DOCTYPE … > <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; > <head> <title>Hello World Code-</title> </head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot; > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public  partial  class  HelloWorldCodeBehind  :  System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.Date.ToString(); } } Page directive HelloWorldCodeBehind.aspx HelloWorldCodeBehind.aspx.cs
Result in the browser <html> <head><title>Hello World Embedded</title></head> <body> <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;HelloWorldEmbedded.aspx&quot; id=&quot;form1&quot;> <input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;  value=&quot;/wEPDwUJODExMDE5NzY5D2QWAgIDD2QWAgIBDw8WAh4EVGV4dAUKMDgvMDEvMjAwNmRkZDZPhFHJER4chf3nmlgfL+uq4W58&quot; /> <h1>Hello World</h1> The date is <em> <span id=&quot;myDate&quot;>23/06/2006</span>  </em> </form> </body> </html> Notice no  <asp:Label>  control. Notice also the hidden input tag with the name of __VIEWSTATE. We will learn more about this view state in Chapter 2.
Web Application Structure An ASP.NET web application can simply consist of a folder containing web forms and other files.  You can, however, add any number of additional nested subfolders within this root folder.  ASP.NET in fact has a number of reserved application folder names, e.g. App_Code App_Data App_Theme
Configuration File Every folder in a web application can contain an XML-format configuration file named  web.config . This configuration file is used to define security, connection strings, and other configuration information.
Visual Studio While you can create an ASP.NET application in any text editor, using Visual Studio will make developing ASP.NET applications easier. Can also use the free Visual Web Developer 2005/2008/2010 Express Edition.
Visual Studio Web Projects All files, folders, and settings in a Web application created with Visual Studio are contained within conceptual containers called  solutions  and  projects .  Depending upon which way you use Visual Studio to construct your Web application, a solution may contain one or more additional projects as well as additional files and metadata about the project.
Visual Studio Web Projects Visual Studio provides two ways of constructing a Web application with projects.  Project-less  This approach uses the content and structure of the site’s folder to define the contents of the Visual Studio project.  There is no Visual Studio project file; instead, the content of the Web site project is directly inferred by Visual Studio from the folder structure and its contents.  For our course, certainly the recommended approach. Project-based Rather than use the file structure of the site, this approach uses a separate Visual Studio project file (with  .csproj  or  .vbproj  extension) to maintain a list of files that belong to the project.
Testing using IIS If your computer has Microsoft’s IIS installed, then you can run a local IIS website. There are two ways of using a local IIS web site with Visual Studio: you can run the Internet Information Services snap-in from the Windows Control Panel and create an IIS  virtual directory , which is like a pointer that references the physical folder for your web site. you can let Visual Studio create the IIS virtual directory.
Virtual Directories vs Physical Folders
Web Server Controls Normal HTML elements such as  <input> ,  <h1> , and  <select>  are not processed by the server but are sent to and displayed by the browser.  Server controls, in contrast, are tags that are processed by the server.  Each ASP.NET server control has an object model containing properties, methods, and events.  You can use this object model to programmatically interact with the control.
Web Server Controls Web server controls are added to a Web forms page in the same way as any HTML element.  That is, you can type the markup code in Source view, or use drag-and-drop from Design view.  As well, you can also programmatically add controls at runtime.
Web Server Controls ASP.NET defines over 60 built-in Web server controls, all of which have a tag prefix of  asp .  The two possible syntaxes for declaring a server control in your markup are: <tagprefix:tagname ID=&quot;myName&quot; runat=&quot;server&quot;> </tagprefix:tagname> <tagprefix:tagname ID=&quot;myName&quot; runat=&quot;server&quot; />
HTML Server Controls ASP.NET provides a special type of server control called the  HTML server control   that has a different syntax from that shown just previously.  HTML server controls look like standard HTML tags, except for one thing:  They contain a  runat=&quot;server&quot;  attribute.  HTML server controls are HTML elements that contain attributes that make them programmable on the server.  Because HTML server controls only have as much functionality as the available HTML elements, this book does not in fact spend any time working with them.  Instead, it focuses on using the much more powerful Web server controls.
Another Example Please enter your name: <asp:TextBox ID=&quot;name&quot; runat=&quot;server&quot; /> <br /> Choose favorite author: <asp:DropDownList ID=&quot;myList&quot; runat=&quot;server&quot;> <asp:ListItem>Choose an author</asp:ListItem> <asp:ListItem>Atwood</asp:ListItem> <asp:ListItem>Austin</asp:ListItem> <asp:ListItem>Hawthorne</asp:ListItem> <asp:ListItem>Melville</asp:ListItem> </asp:DropDownList> <br /> <asp:Button ID=&quot;btnEnter&quot; Text=&quot;Enter&quot; runat=&quot;server&quot;  OnClick=&quot;btnEnter_Click&quot;  /> <p> <asp:Label ID=&quot;msg1&quot; runat=&quot;server&quot; /> </p> public partial class EventTest : System.Web.UI.Page { /// <summary> /// Event handler will be called each time page is requested /// </summary> protected void Page_Load(object sender, EventArgs e) { msg1.Text = &quot;In Page_Load<br/>&quot;; } /// <summary> /// Event handler for button /// </summary> protected void btnEnter_Click(object sender, EventArgs e) { if (myList.SelectedIndex > 0) { msg1.Text += &quot;Hi &quot; + name.Text + &quot;<br/>&quot;; msg1.Text += &quot;Your favorite author is &quot;; msg1.Text += myList.SelectedItem; } } }
Using AutoPostback <asp:DropDownList ID=&quot;myList&quot; runat=&quot;server&quot;  AutoPostBack=&quot;true&quot;  OnSelectedIndexChanged=&quot;myList_SelectedIndexChanged&quot;  > <asp:ListItem>Choose an author</asp:ListItem> <asp:ListItem>Atwood</asp:ListItem> <asp:ListItem>Austin</asp:ListItem> <asp:ListItem>Hawthorne</asp:ListItem> <asp:ListItem>Melville</asp:ListItem> </asp:DropDownList> public partial class EventTest : System.Web.UI.Page { /// <summary> /// Event handler will be called each time page is requested /// </summary> protected void Page_Load(object sender, EventArgs e) { msg1.Text = &quot;In Page_Load<br/>&quot;; } /// <summary> /// Event handler for list box /// </summary> protected void  myList_SelectedIndexChanged (object sender, EventArgs e) { if (myList.SelectedIndex > 0) { msg1.Text += &quot;Hi &quot; + name.Text + &quot;<br/>&quot;; msg1.Text += &quot;Your favorite author is &quot;; msg1.Text += myList.SelectedItem; } } } generates  postback  request when selection event occurs
Result in Browser (before selection) … <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;EventTest.aspx&quot; id=&quot;form1&quot;> <div> <input type=&quot;hidden&quot; name=&quot;__EVENTTARGET&quot; id=&quot;__EVENTTARGET&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__EVENTARGUMENT&quot; id=&quot;__EVENTARGUMENT&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__LASTFOCUS&quot; id=&quot;__LASTFOCUS&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot; value=&quot;/wEPDwUJMzU4OTQyMTQyD2QWAgIDD2QWBAIDDxBkZBYBZmQCBw8PFgIeBFRleHQFEUluIFBhZ2VfTG9hZDxici8+ZGRkrdXaKhB9hfPCxWw0yH66jFyRptR2Yu651BApr5K68So=&quot; /> </div> <script type=&quot;text/javascript&quot;> //<![CDATA[ var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> <div> <input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot; value=&quot;/wEWCQLE88HoBgL7uPQdAqqc94YFAuuUwb8PAqmgr5IGArOL1q0PAuny6fcEAoDL04ICAuPk/MoLgjX6O/3XiiMK8jlmzLdPmAFL2IAhN5e3vB01z5f+ToY=&quot; /> </div> Please enter your name:  <input name=&quot;name&quot; type=&quot;text&quot; id=&quot;name&quot; />  <br /> Choose favorite author: <select name=&quot;myList&quot;  onchange=&quot; javascript:setTimeout(&#39;__doPostBack(\&#39;myList\&#39;,\&#39;\&#39;)&#39;, 0) &quot;  id=&quot;myList&quot;> <option selected=&quot;selected&quot; value=&quot;Choose an author&quot;>Choose an author</option> <option value=&quot;Atwood&quot;>Atwood</option> <option value=&quot;Austin&quot;>Austin</option> <option value=&quot;Hawthorne&quot;>Hawthorne</option> <option value=&quot;Melville&quot;>Melville</option> </select><br /> <input type=&quot;submit&quot; name=&quot;btnClick&quot; value=&quot;Submit&quot; id=&quot;btnClick&quot; /> <p><span id=&quot;msg1&quot;>In Page_Load<br/></span></p> </form> Notice that both Javascript and HTML was generated  by ASP.NET when the page executed.

More Related Content

What's hot (20)

PDF
MEAN Vs MERN Stack | Detailed Comparison Between MEAN & MERN Stack
Mariya James
 
PPT
ASP.NET AJAX with Visual Studio 2008
Caleb Jenkins
 
PDF
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
PPTX
10 practices that every developer needs to start right now
Caleb Jenkins
 
PDF
Server and client rendering of single page apps
Thomas Heymann
 
PPT
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
PPTX
Bridging the Gap: Single-Page Apps and AEM
rbl002
 
PDF
Building Desktop RIAs with PHP, HTML & Javascript in AIR
funkatron
 
KEY
Intro to html5 Boilerplate
Michael Enslow
 
PPTX
HTML5 Bootcamp: Essential HTML, CSS, & JavaScript
Todd Anglin
 
PPT
Intro To Asp Net And Web Forms
SAMIR BHOGAYTA
 
DOC
Asp.Net Tutorials
Ram Sagar Mourya
 
PDF
Build single page applications using AngularJS on AEM
connectwebex
 
PPT
HTML 5 Overview
Offir Ariel
 
PPTX
Web worker in your angular application
Suresh Patidar
 
PPT
Developing an ASP.NET Web Application
Rishi Kothari
 
PPTX
Adobe Flex builder by elmagnif
mbaye camara
 
PPT
Php
Mindtree
 
PDF
Modern JavaScript Frameworks: Angular, React & Vue.js
Jonas Bandi
 
PDF
learn mvc project in 7 day
Quach Long
 
MEAN Vs MERN Stack | Detailed Comparison Between MEAN & MERN Stack
Mariya James
 
ASP.NET AJAX with Visual Studio 2008
Caleb Jenkins
 
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
10 practices that every developer needs to start right now
Caleb Jenkins
 
Server and client rendering of single page apps
Thomas Heymann
 
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
Bridging the Gap: Single-Page Apps and AEM
rbl002
 
Building Desktop RIAs with PHP, HTML & Javascript in AIR
funkatron
 
Intro to html5 Boilerplate
Michael Enslow
 
HTML5 Bootcamp: Essential HTML, CSS, & JavaScript
Todd Anglin
 
Intro To Asp Net And Web Forms
SAMIR BHOGAYTA
 
Asp.Net Tutorials
Ram Sagar Mourya
 
Build single page applications using AngularJS on AEM
connectwebex
 
HTML 5 Overview
Offir Ariel
 
Web worker in your angular application
Suresh Patidar
 
Developing an ASP.NET Web Application
Rishi Kothari
 
Adobe Flex builder by elmagnif
mbaye camara
 
Modern JavaScript Frameworks: Angular, React & Vue.js
Jonas Bandi
 
learn mvc project in 7 day
Quach Long
 

Similar to Web II - 01 - Introduction to server-side development (20)

PPTX
Web development revolution
Ahmed El-Zekred
 
PDF
Sencha Web Applications Come of Age
bastila
 
PDF
Anvita Gita Supersite Case Study Nov2000
guest6e7a1b1
 
PPT
Basic fundamentals of web application development
sofyjohnson18
 
PDF
Asp.net Vs Vue.js.pdf
Integrated IT Solutions
 
PPT
Developing The Web
timoh
 
DOCX
JOB PORTALProject SummaryTitle JOB-PORT.docx
christiandean12115
 
PPSX
01 asp.net session01
Vivek Singh Chandel
 
PPT
Ajax World 2008
Axway Appcelerator
 
PPT
Ajaxworld March 2008 - Jeff Haynie Keynote - Appcelerator
Jeff Haynie
 
PDF
Asp Net Vs Vue JS Which One You Should Choose for Development.pdf
Integrated IT Solutions
 
PPTX
Web Technology Introduction framework.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
01 - Web Programming Intro.pptx
Karina González
 
PDF
Webdevelopment
Giacomo Antonino Fazio
 
PPTX
Gettings started with Web development
Ujjwal Ojha
 
PDF
lec-01-WP.pdf
FumikageTokoyami4
 
PDF
Technologies Which Can be Helpful for Web Application Development
Anna Harris
 
PPTX
Food borne human diseases
AmalMohammedNasserSa
 
PPT
Decoding the Web
newcircle
 
PPT
Overview of Web Technology Intro
webhostingguy
 
Web development revolution
Ahmed El-Zekred
 
Sencha Web Applications Come of Age
bastila
 
Anvita Gita Supersite Case Study Nov2000
guest6e7a1b1
 
Basic fundamentals of web application development
sofyjohnson18
 
Asp.net Vs Vue.js.pdf
Integrated IT Solutions
 
Developing The Web
timoh
 
JOB PORTALProject SummaryTitle JOB-PORT.docx
christiandean12115
 
01 asp.net session01
Vivek Singh Chandel
 
Ajax World 2008
Axway Appcelerator
 
Ajaxworld March 2008 - Jeff Haynie Keynote - Appcelerator
Jeff Haynie
 
Asp Net Vs Vue JS Which One You Should Choose for Development.pdf
Integrated IT Solutions
 
Web Technology Introduction framework.pptx
Kongu Engineering College, Perundurai, Erode
 
01 - Web Programming Intro.pptx
Karina González
 
Webdevelopment
Giacomo Antonino Fazio
 
Gettings started with Web development
Ujjwal Ojha
 
lec-01-WP.pdf
FumikageTokoyami4
 
Technologies Which Can be Helpful for Web Application Development
Anna Harris
 
Food borne human diseases
AmalMohammedNasserSa
 
Decoding the Web
newcircle
 
Overview of Web Technology Intro
webhostingguy
 
Ad

More from Randy Connolly (20)

PDF
Celebrating the Release of Computing Careers and Disciplines
Randy Connolly
 
PDF
Public Computing Intellectuals in the Age of AI Crisis
Randy Connolly
 
PDF
Why Computing Belongs Within the Social Sciences
Randy Connolly
 
PDF
Ten-Year Anniversary of our CIS Degree
Randy Connolly
 
PDF
Careers in Computing (2019 Edition)
Randy Connolly
 
PDF
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Randy Connolly
 
PDF
Where is the Internet? (2019 Edition)
Randy Connolly
 
PDF
Modern Web Development (2018)
Randy Connolly
 
PDF
Helping Prospective Students Understand the Computing Disciplines
Randy Connolly
 
PDF
Constructing a Web Development Textbook
Randy Connolly
 
PDF
Web Development for Managers
Randy Connolly
 
PDF
Disrupting the Discourse of the "Digital Disruption of _____"
Randy Connolly
 
PDF
17 Ways to Fail Your Courses
Randy Connolly
 
PDF
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Randy Connolly
 
PPTX
Constructing and revising a web development textbook
Randy Connolly
 
PDF
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Randy Connolly
 
PDF
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly
 
PDF
Thinking About Technology
Randy Connolly
 
PDF
A longitudinal examination of SIGITE conference submission data
Randy Connolly
 
PDF
Web Security
Randy Connolly
 
Celebrating the Release of Computing Careers and Disciplines
Randy Connolly
 
Public Computing Intellectuals in the Age of AI Crisis
Randy Connolly
 
Why Computing Belongs Within the Social Sciences
Randy Connolly
 
Ten-Year Anniversary of our CIS Degree
Randy Connolly
 
Careers in Computing (2019 Edition)
Randy Connolly
 
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Randy Connolly
 
Where is the Internet? (2019 Edition)
Randy Connolly
 
Modern Web Development (2018)
Randy Connolly
 
Helping Prospective Students Understand the Computing Disciplines
Randy Connolly
 
Constructing a Web Development Textbook
Randy Connolly
 
Web Development for Managers
Randy Connolly
 
Disrupting the Discourse of the "Digital Disruption of _____"
Randy Connolly
 
17 Ways to Fail Your Courses
Randy Connolly
 
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Randy Connolly
 
Constructing and revising a web development textbook
Randy Connolly
 
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Randy Connolly
 
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly
 
Thinking About Technology
Randy Connolly
 
A longitudinal examination of SIGITE conference submission data
Randy Connolly
 
Web Security
Randy Connolly
 
Ad

Recently uploaded (20)

PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Digital Circuits, important subject in CS
contactparinay1
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 

Web II - 01 - Introduction to server-side development

  • 1. SERVER-SIDE DEVELOPMENT An Introduction 01
  • 2. Overview Introduces the nature and structure of ASP.NET. Illustrates how to use Microsoft Visual Studio 2005 Tutorial walkthroughs for creating some sample ASP.NET Web forms using Visual Studio. in-depth coverage of how ASP.NET works is left to the next chapter.
  • 3. What is server-side development? Refers to software development for applications in which the majority of processing occurs on one or more servers (and not on the client’s machine).
  • 4. Static vs Dynamic Web Pages Most web pages that you view are not static HTML pages. Instead they are output from programs that run on servers. These programs can interact with server resources like databases and XML Web services.
  • 7. Dynamic Web Technologies There are quite a number of different technologies for dynamically generating Web content on servers. ASP.NET ASP CGI ColdFusion JSP PHP Ruby on Rails
  • 8. Dynamic Web Technologies All of these technologies share one thing in common: Using programming logic, they generate HTML+CSS+Javascript on the server and send it back to the requesting browser.
  • 10. What is not a Dynamic Server Technology Normal Javascript is not a dynamic server technology. Javascript is a simple programming language that is executed by the browser, not the server. It is embedded within the HTML that is sent to the browser. It can interact with a server, but it executes after the page is received by the browser. <body> <p>Blah blah blah … <script language=&quot;Javascript&quot;> document.write(&quot;This is dynamic client-generated content&quot;); something.InnerHTML = &quot;This is not server-generated&quot;; </script>
  • 11. What is not a Dynamic Server Technology Flash is not a dynamic server technology. Flash refers the Shockwave Flash file (SWF) that is sent to the browser. Your browser, via the Flash Player plug-in, is able to run and display the SWF file. Typically used for advertisement banners, games, or richer user interfaces than are possible with HTML. It can interact with a server, but it executes after the page is received by the browser.
  • 12. Types of Dynamic Technology There are a quite a number of different technologies for dynamically generating web content on the server. All of these technologies share one thing in common: Using programming logic they generate HTML on the server and send it back to the requesting browser. We could categorize dynamic technology into three different types: Direct Output Page Scripting Hybrid
  • 13. Direct Output In such a case, programs running on the server directly output HTML back to the client. CGI and Java Servlets are examples. Advantage is fast execution time. Main drawback is that any change in the design of a web page, no matter how minor, requires of intervention of programmer, who must compile the code (and perhaps turn off server to deploy).
  • 14. Direct Output example public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType(&quot;text/html&quot;); PrintWriter out = response.getWriter(); out.println(&quot;<html>&quot;); out.println(&quot;<body>&quot;); out.println(&quot;<head>&quot;); out.println(&quot;<title>Hello World!</title>&quot;); out.println(&quot;</head>&quot;); out.println(&quot;<body>&quot;); out.println(&quot;<h1>Hello World!</h1>&quot;); out.println(&quot;</body>&quot;); out.println(&quot;</html>&quot;); } }
  • 15. Page Scripting Due to the inefficiencies and difficulties in creating direct output web applications, page scripting dynamic content systems have been developed. That is, scripts embedded within HTML. HTML for static elements, scripts for dynamic elements. Each page contains the scripts it needs. Examples Microsoft's ASP, Allaire's ColdFusion, PHP. All of these systems using scripting languages . These languages are interpreted by the server rather than compiled using a compiler. Advantage: rapid development times for developers. Disadvantage: slower execution speed.
  • 16. Example PHP Script <?php require_once(&quot;utilities/header.php&quot;); ?> <?php $currentTime = date(&quot;F j, Y, g:i a&quot;); $colors = array('white','black','red','green','blue','yellow','orange'); ?> <html> <head></head> <body> <form> The time is now <? echo $currentTime; ?> <br/> Choose a color: <select> <? for ($i=0; $i<count($colors); $i++) { echo '<option>'; echo $colors[$i]; echo '</option>'; } ?> </select> </form> </body> </html>
  • 17. Page Scripting Page scripting systems such as ASP and PHP are great for rapidly developing simple web sites. They can, however, be harder to use when creating large, complex sites Be hard to maintain since the code created tends not be object-oriented.
  • 18. Hybrid More recent technologies such as Microsoft's ASP.NET and Sun's JSP use a hybrid approach and combine the direct output and page scripting models. Disadvantage Hard to learn compared to page scripting Advantage Can use modern software engineering best practices thus making it easier to create large complex sites as well as easier to manage and maintain.
  • 19. Hybrid <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head runat=&quot;server&quot;><title>Scrolling Grid</title></head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot;> <div> <h1>GridView</h1> <asp:GridView ID=&quot;grdvSample&quot; runat=&quot;server&quot; DataSourceID=&quot;myAccess&quot; GridLines=&quot;none&quot; Font-Size=&quot;x-small&quot; Font-Names=&quot;tahoma&quot; BorderColor=&quot;black&quot; BorderWidth=&quot;1&quot;> <HeaderStyle ForeColor=&quot;white&quot; BackColor=&quot;brown&quot; Font-Bold=&quot;true&quot; /> <RowStyle BackColor=&quot;palegoldenrod&quot; /> <AlternatingRowStyle BackColor=&quot;beige&quot; /> </asp:GridView> <asp:AccessDataSource ID=&quot;myAccess&quot; runat=&quot;server&quot; DataFile=&quot;~/App_Data/ModernEyeCatalog.mdb&quot; SelectCommand=&quot;Select ArtistId,LastName,FirstName,Nationality,YearOfBirth,YearOfDeath from Artists&quot; /> </div> </form> </body> </html> public class CustomPaging : System.Web.UI.Page { public void SortGrid( Object o, DataGridSortCommandEventArgs e) { // determine which column is to be sorted string sortField = e.SortExpression; // we must rebind data using the sort field BindData(sortField); } }
  • 20. New Approaches to Dynamic Technology AJAX Asynchronous Javascript with XML is a new technology that combines dynamic server technology, XML, and Javascript to create web applications that are closer to Windows applications or Flash interfaces in their interactivity abilities. E.g., Google Maps and Google Gmail. Dynamic server technology used to retrieve and generate XML data back to browser. Browser then temporarily stores this XML data and uses Javascript to create richer user interface and retrieve data from XML. If user changes XML data, it can be sent back to server for more processing.
  • 21. What do you need for server development? Web server hardware A server is a computer that serves information to other computers. Obviously needs to be powerful enough to handle the requests Web server software Software whose purpose is to deliver web content to HTTP requestors.
  • 22. Web Server Software Apache Open source, often on Linux/Unix OS IIS Microsoft on Windows
  • 23. ASP.NET Web Server Options To test or run ASP.NET Web applications, web server software is necessary. Microsoft’s production web server software is Internet Information Services (IIS). In order to run IIS, your computer’s operating system must be one of the following: Windows 2000, Windows XP Professional (not XP Home), Windows Vista Business or Ultimate (not Vista Home Basic), Windows Server 2003. Windows Server 2008 Windows 7
  • 24. Visual Studio File Server One of the advantages of using Visual Studio for ASP.NET development is that your site can be run and tested with or without using IIS. That is, Visual Studio comes with its own web server software so that you can test execute ASP.NET pages on the same computer. The Visual Studio web server can run locally on all current versions of Windows. The Visual Studio Web server accepts only localhost requests. It cannot serve pages to another computer, and is therefore suitable only for testing pages locally.
  • 25. Web Server Options With Visual Studio, we could say that your computer is a development server (available only to yourself). Alternately, you might upload your work to a staging server running IIS for team testing. Of course, if you want others to see this Web application, it must eventually be uploaded to a production server (available to your Web application’s audience).
  • 27. What is ASP.NET? ASP.NET 4.0 is the current version of ASP.NET, Microsoft’s powerful technology for creating dynamic Web content. ASP.NET is one of the key technologies of Microsoft's .NET Framework. It is the successor to Active Server Pages (ASP).
  • 28. ASP.NET Advantages ASP.NET provides a number of advantages compared to Microsoft’s earlier, &quot;classic&quot; ASP technology. Better performance More powerful development environment Easier maintenance Smoother deployment and configuration
  • 29. A Digression That May Be Skipped .NET Framework
  • 30. The .NET Framework Many of the advantages that ASP.NET provides in comparison to other dynamic Web technologies are a result of its integration into Microsoft’s .NET Framework . The .NET Framework is a development framework that provides a new programming interface to Windows services and APIs, and integrates a number of technologies that emerged from Microsoft during the late 1990s. The .NET Framework is also a software platform for the running and deployment of Windows-based software systems
  • 31. Core Features of .NET Language interoperability Fully object-oriented languages Common runtime engine shared by all languages Base class library usable by all languages Simplified deployment Better security Better performance
  • 32. .NET Framework 3.0 In June 2006, Microsoft combined a number of new Windows development technologies and branded them as the .NET Framework 3.0 This .NET Framework 3.0 includes: Windows CardSpace, Windows Communication Foundation (formerly “Indigo”), Windows Presentation Foundation (formerly “Avalon”), Windows Workflow Foundation (formerly “WinFx”) .NET Framework 2.0.
  • 33. .NET Framework 3.5 Released November 2007 Coincided with release of Visual Studio 2008 Added some language features to C# Added LINQ (Language Integrated Query) Added ASP.NET AJAX
  • 34. .NET Framework 4.0 Released April 2010 Coincided with release of Visual Studio 2010 Added some language features to C# Support for some new .NET languages (IronRuby,IronPython,F#)
  • 35. .NET Architecture The .NET Framework &quot;sits&quot; on top of the Windows operating system. Consists of the following components: Language compilers Common Language Runtime .NET Framework Base Class Library Source: Lam and Tai, .NET Framework Essentials, 3 rd Edition (O'Reilly, 2003).
  • 37. Language Compilers .NET languages can interoperate . This means that you can use multiple .NET languages within a single .NET application. The Microsoft provided languages are: Visual Basic.NET (VB.NET), C#, JScript.NET, C++, J++ Other .NET languages are available from third-parties. Nonetheless, most .NET applications are written using a single language Doing so generally makes an application easier to maintain and support in the long run. Language interoperability is, however, often utilized whenever a .NET application makes use of someone else’s compiled class libraries.
  • 38. How is language interoperability achieved? All .NET languages must follow the rules in the Common Language Specification ( CLS ). These rules define a subset of common data types and programming constructs that all .NET languages must support. All .NET languages are compiled into a common format. All code is compiled into Microsoft Intermediate Language ( MSIL ), also called Common Intermediate Language (CIL or simply IL), rather than binary.
  • 39. MSIL MSIL is a CPU-independent virtual machine language analogous to Java’s bytecode. It consists of CPU-independent instructions for loading/storing information and calling methods. MSIL is not itself interpreted or executed. The Common Language Runtime (CLR, covered shortly) converts the MSIL into managed native binary code at runtime using the Just-In-Time compiler as methods are called.
  • 41. Assemblies MSIL is physically stored within special containers called assemblies . While these assemblies have familiar extensions (e.g., DLL or EXE), they are quite different from traditional Windows DLL or EXE files.
  • 42. Assemblies A .NET assembly contains MSIL instructions metadata that includes type definitions, version information, external assembly references, and other info. This metadata allows different components, tools, and runtimes to work together. The CLR uses this metadata for verification, security enforcement, and other tasks. For this reason, .NET assemblies are said to contain managed code , in that the CLR manages the memory utilization and execution of the code.
  • 43. Sample MSIL Assembly ... .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 1:0:5000:0 } .assembly hello { .hash algorithm 0x00008004 .ver 0:0:0:0 } .module hello.exe // MVID: {F828835E-3705-4238-BCD7-637ACDD33B78} .class private auto ansi beforefieldinit MainApp extends [mscorlib]System.Object { .method public hidebysig static void Main( ) cil managed { .entrypoint .maxstack 1 ldstr &quot;C# hello world!&quot; call void [mscorlib]System.Console::WriteLine(string) ret } // End of method MainApp::Main .method public hidebysig specialname rtspecialname instance void .ctor( ) cil managed { .maxstack 1 ldarg.0 call instance void [mscorlib]System.Object::.ctor( ) ret } // End of method MainApp::.ctor } // End of class MainApp If we use the IL disassembler ( ildasm.exe ) to turn a binary assembly into a text assembly, we will see something similar to the following: Metadata MSIL Module
  • 44. Common Language Runtime (CLR) The CLR is the execution engine for .NET framework applications. provides a common runtime environment for the execution of code written in any of the .NET languages. It is a software-only, virtual platform that abstracts functionality from the operating system platform.
  • 45. CLR Conceptually, the CLR and Java's JVM are similar in that they are both runtime infrastructures that abstract the underlying platform differences. However, while the JVM officially supports only the Java language, the CLR supports multiple languages The JVM executes bytecode, so it too could, in principle, support languages other than Java. Unlike Java's bytecode, though, .NET's MSIL is never interpreted. Another conceptual difference is that Java code runs on any platform with a JVM, whereas .NET code runs only on platforms that support the CLR (currently only Windows).
  • 46. .NET Framework Base Class Library The .NET Framework base class library (BCL) is a large set of standard classes and other types. This library includes classes for: working with the base types and exceptions, representing common data structures and collections, performing data access, constructing Windows and Web interfaces.
  • 47. BCL These classes are hierarchically organized into logical containers called namespaces . These namespaces are somewhat analogous to Java packages, except that .NET namespaces, unlike Java packages, are not also physical containers. Namespaces prevent name clashes e.g., two assemblies each with a class named Image . System.Windows.Forms.Image vs. System.Web.UI.Image Recall that compiled .NET code (i.e., MSIL) is physically stored in assemblies. an assembly can contain classes in multiple namespaces, or classes within a namespace can be physically partitioned across multiple assemblies.
  • 49. .NET Execution .NET programs written in a CLS-compliant language are compiled by the appropriate language compiler into MSIL. The MSIL is persisted into one or more assemblies. The CLR is then involved in the execution of the MSIL-based programs. This involves: The CLR will invoke the JIT (Just-In-Time) compiler as needed to convert the MSIL into the appropriate machine code. The CLR will execute the resulting machine code but manage code-level security and garbage collection.
  • 51. End of .NET Framework digression Back to ASP.NET
  • 52. ASP.NET Versions 1.0, 1.1 Introduced web form model used by ASP.NET 2.0 Added new features: themes, master pages, security, data source controls, web parts, navigation, profiles 3.5 Added LINQ and ASP.NET Ajax support 4.0 Standardized XHTML rendering, charting, search-friendly URLS, optional viewstate ASP.NET MVC add-in.
  • 53. ASP.NET MVC Uses the MVC (Model-View-Controller) pattern Radically different alternative to the web forms model of standard ASP.NET. Doesn’t use web forms, controls, postback, viewstate, sessions, etc.
  • 54. ASP.NET Web Forms An ASP.NET web application : Consists of any number of web pages, controls, programming classes, web services, and other files Residing within a single web server application directory
  • 55. ASP.NET Web Forms The principal component of an ASP.NET web application are its web pages. These are text files with an .aspx extension and are called web forms . Consist of two parts: The declaratively-defined (i.e., by markup/tags) visual elements. The programming logic.
  • 56. Web Form Programming Logic A web form's programming logic can exist in either: The same file as the visual elements i.e., the .aspx file. This code is contained within a code-declaration block . In a separate class file. The file is usually called a code-behind file . By convention, its filename is same as .aspx file but with a language extension. HelloWorld.aspx <- web form HelloWorld.aspx.cs <- code-behind file
  • 57. HelloWorld.aspx Example <%@ Page Language=&quot;C#&quot; %> <!DOCTYPE html PUBLIC … > <script runat=&quot;server&quot;> protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.ToShortDateString(); } </script> <html> <head><title>Hello World Embedded</title></head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot; > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> Web server control Code declaration block Necessary to make this a web form Page directive
  • 58. Code Behind Version <%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;HelloWorldCodeBehind.aspx.cs&quot; Inherits=&quot;HelloWorldCodeBehind&quot; %> <!DOCTYPE … > <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; > <head> <title>Hello World Code-</title> </head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot; > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class HelloWorldCodeBehind : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.Date.ToString(); } } Page directive HelloWorldCodeBehind.aspx HelloWorldCodeBehind.aspx.cs
  • 59. Page Directive The Page directive is used to define page-specific instructions used by the ASP.NET environment. This directive indicates that the programming code in any script blocks will be C#. Directives are processing instructions for the parser and compiler when they process an ASP.NET page. Although directives can be located anywhere in an .aspx file, the standard practice is to place them at the beginning of the file. Directive statements are not case sensitive and quotation marks are not required around the attribute values. <%@ Page Language=&quot;C#&quot; %>
  • 60. <form> element All ASP.NET pages must contain a <form> element that contains this runat attribute. All body content in a Web form should appear within this special <form> element. <form id=&quot;form1&quot; runat=&quot;server&quot; > … </form>
  • 61. <asp:Label> Web Control In the example’s markup, there is an element named <asp:Label> . This is a predefined ASP.NET Web server control (covered in more detail later). The markup for this Label control sets its ID property to the value myDate . The Label control must contain the runat=&quot;server&quot; attribute. If it does not have it, the ASP.NET environment simply passes on the markup to the browser, where it will be ignored. <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label>
  • 62. Programming Logic Code can be contained within: Within code-behind class Within code declaration blocks i.e, within the <script runat=&quot;server&quot;> element Within code render blocks within the markup. i.e., <% inline code here %> Although the use of code render blocks is familiar to ASP programmers, their use is very much discouraged in ASP.NET . In the vast majority of cases, we can replace code render blocks with a combination of server controls and programming within either code declaration blocks or within the page’s code-behind file.
  • 63. Why use code-behind? The real advantage of separating the code into its own file is that it may lead to more maintainable web forms. One of the main benefits of ASP.NET is that a page’s programming logic can be conceptually separated from the presentation by using a code-behind file a page’s programming logic can also be physically separated from the presentation/markup. By placing the programming code into its own file, it is also potentially easier to make use of a division of labor in the creation of the site. Use whichever model you want However, all the examples in text use code-behind.
  • 64. Code Behind Version <%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;HelloWorldCodeBehind.aspx.cs&quot; Inherits=&quot;HelloWorldCodeBehind&quot; %> <!DOCTYPE … > <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; > <head> <title>Hello World Code-</title> </head> <body> <form id=&quot;form1&quot; runat=&quot;server&quot; > <h1>Hello World</h1> The date is <em> <asp:Label ID=&quot;myDate&quot; runat=&quot;server&quot;></asp:Label> </em> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class HelloWorldCodeBehind : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { myDate.Text = DateTime.Now.Date.ToString(); } } Page directive HelloWorldCodeBehind.aspx HelloWorldCodeBehind.aspx.cs
  • 65. Result in the browser <html> <head><title>Hello World Embedded</title></head> <body> <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;HelloWorldEmbedded.aspx&quot; id=&quot;form1&quot;> <input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot; value=&quot;/wEPDwUJODExMDE5NzY5D2QWAgIDD2QWAgIBDw8WAh4EVGV4dAUKMDgvMDEvMjAwNmRkZDZPhFHJER4chf3nmlgfL+uq4W58&quot; /> <h1>Hello World</h1> The date is <em> <span id=&quot;myDate&quot;>23/06/2006</span> </em> </form> </body> </html> Notice no <asp:Label> control. Notice also the hidden input tag with the name of __VIEWSTATE. We will learn more about this view state in Chapter 2.
  • 66. Web Application Structure An ASP.NET web application can simply consist of a folder containing web forms and other files. You can, however, add any number of additional nested subfolders within this root folder. ASP.NET in fact has a number of reserved application folder names, e.g. App_Code App_Data App_Theme
  • 67. Configuration File Every folder in a web application can contain an XML-format configuration file named web.config . This configuration file is used to define security, connection strings, and other configuration information.
  • 68. Visual Studio While you can create an ASP.NET application in any text editor, using Visual Studio will make developing ASP.NET applications easier. Can also use the free Visual Web Developer 2005/2008/2010 Express Edition.
  • 69. Visual Studio Web Projects All files, folders, and settings in a Web application created with Visual Studio are contained within conceptual containers called solutions and projects . Depending upon which way you use Visual Studio to construct your Web application, a solution may contain one or more additional projects as well as additional files and metadata about the project.
  • 70. Visual Studio Web Projects Visual Studio provides two ways of constructing a Web application with projects. Project-less This approach uses the content and structure of the site’s folder to define the contents of the Visual Studio project. There is no Visual Studio project file; instead, the content of the Web site project is directly inferred by Visual Studio from the folder structure and its contents. For our course, certainly the recommended approach. Project-based Rather than use the file structure of the site, this approach uses a separate Visual Studio project file (with .csproj or .vbproj extension) to maintain a list of files that belong to the project.
  • 71. Testing using IIS If your computer has Microsoft’s IIS installed, then you can run a local IIS website. There are two ways of using a local IIS web site with Visual Studio: you can run the Internet Information Services snap-in from the Windows Control Panel and create an IIS virtual directory , which is like a pointer that references the physical folder for your web site. you can let Visual Studio create the IIS virtual directory.
  • 72. Virtual Directories vs Physical Folders
  • 73. Web Server Controls Normal HTML elements such as <input> , <h1> , and <select> are not processed by the server but are sent to and displayed by the browser. Server controls, in contrast, are tags that are processed by the server. Each ASP.NET server control has an object model containing properties, methods, and events. You can use this object model to programmatically interact with the control.
  • 74. Web Server Controls Web server controls are added to a Web forms page in the same way as any HTML element. That is, you can type the markup code in Source view, or use drag-and-drop from Design view. As well, you can also programmatically add controls at runtime.
  • 75. Web Server Controls ASP.NET defines over 60 built-in Web server controls, all of which have a tag prefix of asp . The two possible syntaxes for declaring a server control in your markup are: <tagprefix:tagname ID=&quot;myName&quot; runat=&quot;server&quot;> </tagprefix:tagname> <tagprefix:tagname ID=&quot;myName&quot; runat=&quot;server&quot; />
  • 76. HTML Server Controls ASP.NET provides a special type of server control called the HTML server control that has a different syntax from that shown just previously. HTML server controls look like standard HTML tags, except for one thing: They contain a runat=&quot;server&quot; attribute. HTML server controls are HTML elements that contain attributes that make them programmable on the server. Because HTML server controls only have as much functionality as the available HTML elements, this book does not in fact spend any time working with them. Instead, it focuses on using the much more powerful Web server controls.
  • 77. Another Example Please enter your name: <asp:TextBox ID=&quot;name&quot; runat=&quot;server&quot; /> <br /> Choose favorite author: <asp:DropDownList ID=&quot;myList&quot; runat=&quot;server&quot;> <asp:ListItem>Choose an author</asp:ListItem> <asp:ListItem>Atwood</asp:ListItem> <asp:ListItem>Austin</asp:ListItem> <asp:ListItem>Hawthorne</asp:ListItem> <asp:ListItem>Melville</asp:ListItem> </asp:DropDownList> <br /> <asp:Button ID=&quot;btnEnter&quot; Text=&quot;Enter&quot; runat=&quot;server&quot; OnClick=&quot;btnEnter_Click&quot; /> <p> <asp:Label ID=&quot;msg1&quot; runat=&quot;server&quot; /> </p> public partial class EventTest : System.Web.UI.Page { /// <summary> /// Event handler will be called each time page is requested /// </summary> protected void Page_Load(object sender, EventArgs e) { msg1.Text = &quot;In Page_Load<br/>&quot;; } /// <summary> /// Event handler for button /// </summary> protected void btnEnter_Click(object sender, EventArgs e) { if (myList.SelectedIndex > 0) { msg1.Text += &quot;Hi &quot; + name.Text + &quot;<br/>&quot;; msg1.Text += &quot;Your favorite author is &quot;; msg1.Text += myList.SelectedItem; } } }
  • 78. Using AutoPostback <asp:DropDownList ID=&quot;myList&quot; runat=&quot;server&quot; AutoPostBack=&quot;true&quot; OnSelectedIndexChanged=&quot;myList_SelectedIndexChanged&quot; > <asp:ListItem>Choose an author</asp:ListItem> <asp:ListItem>Atwood</asp:ListItem> <asp:ListItem>Austin</asp:ListItem> <asp:ListItem>Hawthorne</asp:ListItem> <asp:ListItem>Melville</asp:ListItem> </asp:DropDownList> public partial class EventTest : System.Web.UI.Page { /// <summary> /// Event handler will be called each time page is requested /// </summary> protected void Page_Load(object sender, EventArgs e) { msg1.Text = &quot;In Page_Load<br/>&quot;; } /// <summary> /// Event handler for list box /// </summary> protected void myList_SelectedIndexChanged (object sender, EventArgs e) { if (myList.SelectedIndex > 0) { msg1.Text += &quot;Hi &quot; + name.Text + &quot;<br/>&quot;; msg1.Text += &quot;Your favorite author is &quot;; msg1.Text += myList.SelectedItem; } } } generates postback request when selection event occurs
  • 79. Result in Browser (before selection) … <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;EventTest.aspx&quot; id=&quot;form1&quot;> <div> <input type=&quot;hidden&quot; name=&quot;__EVENTTARGET&quot; id=&quot;__EVENTTARGET&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__EVENTARGUMENT&quot; id=&quot;__EVENTARGUMENT&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__LASTFOCUS&quot; id=&quot;__LASTFOCUS&quot; value=&quot;&quot; /> <input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot; value=&quot;/wEPDwUJMzU4OTQyMTQyD2QWAgIDD2QWBAIDDxBkZBYBZmQCBw8PFgIeBFRleHQFEUluIFBhZ2VfTG9hZDxici8+ZGRkrdXaKhB9hfPCxWw0yH66jFyRptR2Yu651BApr5K68So=&quot; /> </div> <script type=&quot;text/javascript&quot;> //<![CDATA[ var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> <div> <input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot; value=&quot;/wEWCQLE88HoBgL7uPQdAqqc94YFAuuUwb8PAqmgr5IGArOL1q0PAuny6fcEAoDL04ICAuPk/MoLgjX6O/3XiiMK8jlmzLdPmAFL2IAhN5e3vB01z5f+ToY=&quot; /> </div> Please enter your name: <input name=&quot;name&quot; type=&quot;text&quot; id=&quot;name&quot; /> <br /> Choose favorite author: <select name=&quot;myList&quot; onchange=&quot; javascript:setTimeout(&#39;__doPostBack(\&#39;myList\&#39;,\&#39;\&#39;)&#39;, 0) &quot; id=&quot;myList&quot;> <option selected=&quot;selected&quot; value=&quot;Choose an author&quot;>Choose an author</option> <option value=&quot;Atwood&quot;>Atwood</option> <option value=&quot;Austin&quot;>Austin</option> <option value=&quot;Hawthorne&quot;>Hawthorne</option> <option value=&quot;Melville&quot;>Melville</option> </select><br /> <input type=&quot;submit&quot; name=&quot;btnClick&quot; value=&quot;Submit&quot; id=&quot;btnClick&quot; /> <p><span id=&quot;msg1&quot;>In Page_Load<br/></span></p> </form> Notice that both Javascript and HTML was generated by ASP.NET when the page executed.