November 25, 2010

ASP.Net - Create Your First ASP.Net

1. Introduction

In this article, we will create our first ASP.Net application using the C# language. This is a Step by Step with an explanation in the middle when it required.

2. Creating the Web Project

1) From the start menu open the Visual studio 2005
2) Click on File|New Web Site
3) From the opened dialog chose ASP.Net web site

4) Set the Location as File System.
5) Set language as Visual C#

6) Set a folder path of your choice for your web site by selecting a Folder using the Browse button. Then click OK.

The Visual Studio 2005 creates the web project and it is ready. Here, we selected File System as the location. So we are not going to deploy it in the IIS. The IIS stands for Internet Information Server. IIS is a web server, which processes the user input, and replies back web page content. Since we had selected file system, the application will be created on your local system and cannot be accessed from the network (Local Intranet or World wide web). But, still you can test it on your local application.

Now you are left at the defalt.aspx page by VS 2005. This is the default page every site displays when a site name is invoked just by giving the Name. Just try on your browser and watch what page it displays by default.

3. Adding controls to your Page

Now we will add a Hyper Link control and button to the default web page. The link control is not visible when the page is displayed. To make it visible the user should click the button Get Link.

1) First click the Design button in the bottom pane of default.aspx. This is shown in the Previous picture. Note that this is how you will switch between design and source.
2) Once you are in the design mode, first select a button control and drag and drop it to the Design area.
3) Next do the same for Hyper link control.

The design area now looks like below:

4) Click the button
5) Select the menu item View|Properties window
6) From the displayed property window on the Right side pane, set the following properties shown in bold for the Selected button control

7) Click the Hyperlink control and set the properties as shown below:

8) Now Click the Save all Icon from the Toolbar.

4. Adding the event handler

Now we will add the event handler for the button click event. And the handler will take care of setting the visible property for the Hyperlink control to true. When you double click the button Visual studio 2005 will bring you to a C# file called Default.aspx.cs. This file is called code behind file. Code behind – because it takes care writing the logic behind the page Default.aspx. Some people also call it as supporting file. Supporting file for what? Supporting file for the Default.aspx server side script file.

1) Double click the button control
2) Visual studio will bring you to the code behind page. Write the following line of code:

//001: Set the visibilty of the Hyper link to true
HyperLink1.Visible = true;

5. Running Your First web application

1) Click on the Run Icon

2) The following message box displays. Click ok for the Message box.

3) Visual studio invokes the Inbuilt Web server (Like IIS) and displays the Web page designed by you. Click the Show Link button. This will show the Web URL.

6. How Do I open the Attached Project

1) Download the attached zip file
2) Extract it to a folder
3) Open visual studio 2005
4) Click the menu item File|Open|Web site
5) Select the Extracted Folder

Note: The Attached solution is created in visual studio 2005

Source Code : Download

No comments:

Post a Comment

Leave your comment(s) here.

Like this site? Tell it to your Friend :)