Creating and Configuring a Web Application Using C# .NET

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

Creating and Configuring a Web Application Using C# .NET

Rating:

In Visual Studio .NET, a Web application is used to provide information from a Web server to different client users over the Internet. It uses Hypertext Transfer Protocol (HTTP) to send requests from the client Web browser to the Web application on the Web server, and to return the application’s responses to the client over the Internet. In Visual Studio 2005, Web projects are known as Web sites. Therefore, a new Web site can be of four types, which are as follows:

  • File-based Web site:


  • FTP-based Web site:


  • Local HTTP-based Web site:


  • Remote HTTP-based Web site:
In Visual Studio .NET, a solution is a structure that contains a group of one or more projects that are organized in Visual Studio. These projects work together to create a Web-based, Windows-based or a console application. All the status and project information of a particular solution are stored in two types of solution files. These solution files are the .sln and .suo files that store settings of a specific solution.

ASP.NET Web Application Structure

A Web form, also known as a Web page of an ASP.NET Web application, collects data that a user requests or submits from a Web page. A Web page is created with an .aspx extension file. It comprises three sections: page directives, code, and page layout. Each section is briefly described in the following manner:
  • Page Directives: Page directives is the first section of an ASP.NET Web page. This section is used to set up the environment on how the page should be processed. In this section, namespaces can be imported and assemblies can be loaded. The code is written in a Web page in the following manner:

    <%@ Page Language="C#" %>


  • Code: The code section of a Web page consists of code to handle events that a user has requested from one of the controls of the Web page. This section contains the script block in which all the event-related code are written inside the <script> tag. For example:

    <script runat="server">
    private void CommandButton1_Click(object sender, System.EventArgs event)
    {
       TextBox Text1 = new TextBox();
       Text1.Location = new Point(30,30);
       this.Controls.Add (Text1);
    }
    </script>


    Note: In the above code, the runat="server" indicates that the code will run on the server.


  • Page Layout: The page layout is the last section of a Web page. It consists of HTML body containing simple text, client and server controls. For example:

    <html>
    <head>
    <title>My first server control</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:Button id="CommandButton1" runat="server"
    onclick="CommandButton1_Click" Text="ClickButton" >
    </asp:Button>
    </form>
    </body>
    </html>
Adding Web Pages to a Web Site

After creating a Web site, a user can add one or more Web pages to the currently opened Web site. Select the Website > Add New Item... menu option from the menu toolbar, as shown below:



The Add New Item dialog box appears. Select the Web Form option from the Visual Studio installed templates under the Templates option. In the text box of the Name option, type an appropriate name of the Web form. Select the default Visual C# language option from the Language drop-down list. Check either one or both the Place code in separate file and the Select master page checkbox options. Finally, click the Add button. The Add New Item dialog box is shown below:



ASP.NET Programming Model

In .NET Framework, an ASP.NET page writes both Visual Studio and HTML code, which form a simple Web page. The HTML code represents the user interface of a Web application, whereas the Visual Studio code identifies the business logic of the application. This type of model is known as the in-line programming model. However, ASP.NET 2.0 has provided a model known as the code-behind programming model. This model separates the HTML code that specifies the user interface of a Web application in one file with an .aspx extension, with that of the business logic of the application in another file with an .cs extension. These two files are linked in the Web page by using the Page directive of the ASP.NET. When the Web page is compiled, the ASP.NET compiler examines the Page directive and locates the business logic associated with the user interface in the .aspx page.

Dynamic Compilation of a Web Site




Rating:



Other articles

Click here to Article home

Microsoft Certification MCSE: MCSA , MCTS, MCDST, MCAD, MCDBA, MCSE Messaging, MCSE Security
JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.