ASP.Net Web Site Sample

by Shabbir on April 28, 2008

in ASP.Net

Today we will create a simple ASP.Net web site.

You must have Visual Studio or Visual Web Deleloper to start creating web sites with ASP.Net.

We will use Visual Studio 2008.

To start go to File -> New -> Web Site (Shift+Alt+N). In the dialog box under the Templates area select ASP.NET Web Site, set the Location to File System, set the Language to Visual C#, and specify the directory where the project will be created.

Creating web site

Then press OK, and the project will be created, and you will see the Default.aspx source code. Will be something like this

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
    </div>
</form>
 
</body>
</html>

Between the div tags insert this code

<asp:Button ID="button1" Text="Button" OnClick="button1Click"
 runat="server"/>
<asp:TextBox ID="textBox1" runat="server"/>
<br>
<h4><asp:Label ID="label1" runat="server"/></h4>
 

With this we are creating a button control, with text Button, its ID is button1 and a click event, also we are creating a textbox and a label.

Above head tag, insert this

<script runat="server">
    void button1Click(object Source, EventArgs e)
    {
        label1.Text = "TextBox text: " + textBox1.Text;
    }    
</script>

Here we are defining the function, which will be called when the button is clicked.
It, will change the label text.

Debug the project (F5), and the web page will be opened, it will be something like this

Sample asp

Now write something in the textbox, and click the button. You will get this

Sample asp web site

So, with clicking the button, the label text property is changing to "TextBox text: " + the text we write in the text box.

Sharing is Caring...

Other Related Posts:

  1. Creating a Windows Forms Application in C#
  2. ASP.Net Database Connection
  3. Adding Items to ListView Control
  4. Adding Items to ListBox and ComboBox Controls
  5. Remove Unused Using Statements

Leave a Comment

Spam protection by WP Captcha-Free

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.