Friday, March 14, 2014

Asp.NET : Add ListItem to BulletedList

Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

    <h1 style="border-style: dashed; border-color: #008000; font-family: Valken; color: #000080">BulletedList</h1>

    <asp:BulletedList runat="server" ID="bl1">
        <asp:ListItem>Mahi</asp:ListItem>
        <asp:ListItem>Appy</asp:ListItem>
        <asp:ListItem>Ruzin</asp:ListItem>
    </asp:BulletedList>

    </form>
</body>
</html>

Default.aspx.cs :-


public partial class _Default : System.Web.UI.Page
{
    const int count = 10;

    string GetDisplayItem(int n)
    {
        return n.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        bl1.Items.Clear();

        for (int i = 1; i <= count; i++)
            bl1.Items.Add(new ListItem(GetDisplayItem(i)));

        base.OnLoad(e);
    }
}

Output:-


Asp.NET : Hyperlink

Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   <div id="container">
      <h1>HyperLink Example</h1>
      Use list to specify link:<br /><br />
       <asp:DropDownList
            ID="DropDownList1"
            AutoPostBack="True"
            runat="server"
           onselectedindexchanged="DropDownList1_SelectedIndexChanged">

       <asp:ListItem>Select any social site : </asp:ListItem>
        <asp:ListItem>facebook</asp:ListItem>
        <asp:ListItem>twitter</asp:ListItem>
        <asp:ListItem>pinterest</asp:ListItem>

       </asp:DropDownList><br /><br />
      Here is a link:
         <asp:HyperLink ID="hypTest" Runat="server" />
   </div>
   </form>
</body>
</html>

Default.aspx.cs :-


protected void Page_Load(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 0)
            hypTest.Visible = false;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            string site = DropDownList1.SelectedItem.Text;
            hypTest.Visible = true;
            hypTest.Text = site;
            hypTest.ToolTip = "Go to the web site of " + site;
            hypTest.NavigateUrl = "http://www." + site + ".com";
        }
    }

Output:-



Asp.NET : onmouseover and onmouseout

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" ForeColor="#FF0066"
            onmouseover="this.value='Click'"
            onmouseout="this.value='Mahi'"
            style="margin-left: 371px" Text="Mahi" />
    </div>
    </form>
</body>
</html>

Asp.NET : Simple pizza order example.

Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container">
      <h1>My Online Pizza Shop</h1>
      <div class="box">
         Delivery:
         <asp:CheckBox ID="chkDelivery" runat="server"
            OnCheckedChanged="CheckChanged" AutoPostBack="True" />
            <asp:Label ID="labAddress"
                       runat="server"
                       Text="Your Address please: "
                       Visible="false" /><br />
            <asp:TextBox ID="txtAddress"
                         runat="server"
                         Columns="60"
                         Visible="False" /><br />
         Pizza Styles: <br />
         <asp:CheckBox ID="chkThin" runat="server" Text="Thin Crust" />
         <br />
         <asp:CheckBox ID="chkExtra" runat="server" Text="Extra Sauce" />
      </div>

      <asp:Button ID="btnOrder" runat="server"
         Text="Order" OnClick="btnOrder_Click" style="margin-left: 111px" /><br />
      <strong><asp:Label ID="labMessage" runat="server" ForeColor="#FF3399" /></strong>
   </div>
    </form>
</body>
</html>

Default.aspx.cs :-


protected void CheckChanged(object sender, System.EventArgs e)
    {
        if (chkDelivery.Checked)
        {
            txtAddress.Visible = true;
            labAddress.Visible = true;
        }
        else
        {
            txtAddress.Visible = false;
            labAddress.Visible = false;
        }
    }
    protected void btnOrder_Click(object sender, EventArgs e)
    {
        labMessage.Text = "Your Order is: <br/>";
        if (chkThin.Checked)
            labMessage.Text += chkThin.Text +" Pizza<br/>";
        if (chkExtra.Checked)
            labMessage.Text += chkExtra.Text +" Pizza<br/>";
    }

Output:


Asp.net : Simple example of 2value calculator

Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

        Number 1: <asp:textbox id="tbNumber1" runat='server'/><br />
        Number 2: <asp:textbox id="tbNumber2" runat='server'/>
        <asp:Button ID="Button1" runat="server" style="margin-left: 13px"
            Text="  +  " onclick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" style="margin-left: 13px"
            Text="  -  " onclick="Button2_Click" />
        <asp:Button ID="Button3" runat="server" style="margin-left: 13px"
            Text="  *  " onclick="Button3_Click" />
        <asp:Button ID="Button4" runat="server" style="margin-left: 17px" Text="  /  "
            Width="34px" onclick="Button4_Click" /><br />
        <asp:label id="lblMessage" font-size="20pt" runat='server'/>

    </form>
</body>
</html>

Default.aspx.cs :-


protected void Button1_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) + Convert.ToInt32(tbNumber2.Text)).ToString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) - Convert.ToInt32(tbNumber2.Text)).ToString();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) * Convert.ToInt32(tbNumber2.Text)).ToString();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) / Convert.ToInt32(tbNumber2.Text)).ToString();
    }

Output:-



Wednesday, March 12, 2014

Asp.NET Managing State.

HTTP ( Hyper Text Transfer Protocol) is a stateless protocol. When the client disconnects from the server, the ASP.Net engine discards the page objects. This way each web application can scale up to serve numerous requests simultaneously without running out of server memory.

If we have to track the users' information between page visits and even on multiple visits of the same page, then we need to use the State management techniques provided by ASP.NET. State management is the process by which ASP.NET let the developers maintain state and page information over multiple request for the same or different pages.

Types of State Management :-


Client side state management
Server side state management

Client side state management techniques


  • View State
  • Control State
  • Hidden fields
  • Cookies
  • Query Strings


Server side state management techniques


  • Application State
  • Session State

Tuesday, March 11, 2014

Asp.NET Validation - CustomValidator

The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation.

The client side validation is accomplished through the ClientValidationFunction property. The client side validation routine should be written in a scripting language, like JavaScript or VBScript, which the browser can understand.

The server side validation routine must be called from the control.s ServerValidate event handler. The server side validation routine should be written in any .Net language, like C# or VB.Net.

Example:-
Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Enter Text :
        <asp:TextBox runat="server" id="txtCustom" />
        <asp:CustomValidator
            runat="server" id="cv" controltovalidate="txtCustom"
            onservervalidate="cv_ServerValidate"
            errormessage="The text must be exactly 8 characters long!"
            BackColor="#009900" ForeColor="White" />
        <br /><br />
    </div>
    </form>
</body>
</html>

in Default.aspx.cs :-


protected void cv_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        if (e.Value.Length == 8)
            e.IsValid = true;
        else
            e.IsValid = false;
    }

Output:


Asp.NET Validation - RegularExpressionValidator

The RegularExpressionValidator allows validating the input text by matching against a pattern against a regular expression. The regular expression is set in the ValidationExpression property.

Example:-
default.aspx:-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Email Validate</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    <asp:Label
        id="lblEmail"
        Text="Email Address:"
        AssociatedControlID="txtEmail"
        Runat="server" />
    <asp:TextBox
        id="txtEmail"
        Runat="server" />
    <asp:RegularExpressionValidator
        id="regEmail"
        ControlToValidate="txtEmail"
        Text="(Invalid email)"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        Runat="server" ForeColor="#FF0066" />  
   
    <br /><br />
   
    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" />
   
    </div>
    </form>
</body>
</html>

Output:


Asp.NET Validation - RangeValidator

The RangeValidator control verifies that the input value falls within a predetermined range.

Example:-
Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body bgcolor="White">
    <form id="form1" runat="server">
    <div>
    <h3>Date:<asp:TextBox runat="server" id="txtDate" />

        </h3>
        <br />

        <asp:RangeValidator
            runat="server" id="rngDate" controltovalidate="txtDate" type="Date"
            minimumvalue="01-01-2014" maximumvalue="31-12-2014"
            errormessage="Please enter a valid date within 2014!"
            BorderColor="#FF3399" BorderStyle="Ridge" ForeColor="Red" />
    </div>
    </form>
</body>
</html>

Output:


Asp.NET Validation - CompareValidator

The CompareValidator control compares a value in one control with a fixed value, or, a value in another control.

Example:-
Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

        First number:<br />
        <asp:TextBox runat="server" id="n1" /><br /><br />

        Last number:<br />
        <asp:TextBox runat="server" id="n2" />
        <br />
        <br />

        <asp:CompareValidator
            runat="server" id="cmpNumbers" controltovalidate="n1"
            controltocompare="n2" operator="Equal" type="Integer"
            errormessage="Both numbers are not equal!" BorderColor="#FF0066"
            BorderStyle="Solid" /><br />
    </div>
    </form>
</body>
</html>

Output:


Asp.NET Validation - RequiredFieldValidator

The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box.

Example :-
Deafault.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Required Validator</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     
    <asp:Label
        id="lblFirstName"
        Text="First Name"
        AssociatedControlID="txtFirstName"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtFirstName"
        Runat="server" />
    <asp:RequiredFieldValidator
        id="reqFirstName"
        ControlToValidate="txtFirstName"
        Text="Must enter your first name."
        SetFocusOnError="true"
        Runat="server" ForeColor="#FF0066" />
   
    <br /><br />
     
    <asp:Label
        id="lblLastName"
        Text="Last Name"
        AssociatedControlID="txtLastName"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtLastname"
        Runat="server" />
    <asp:RequiredFieldValidator
        id="reqLastName"
        ControlToValidate="txtLastName"
        Text="Must enter your last name"
        SetFocusOnError="true"
        Runat="server" ForeColor="#FF0066" />
   
     <br /><br />
   
     <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" onclick="btnSubmit_Click" />

        <br />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server"></asp:Label>

    </div>
    </form>
</body>
</html>

Now add code in the Default.aspx.cs :-


protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Label1.Text = txtFirstName.Text;
        Label2.Text = txtLastname.Text;
    }

Output:



Asp.NET : Raise event from User Control to Default Page

Create a new project.
add item -> select "Web User Control" -> add
Write the following code in WebUserControl.ascx file :-


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>

<asp:Button ID="btnTest" runat="server" Text="This is from User Control"
    OnClick="btnTest_Click" ForeColor="#FF0066" />

Then add code in the button event
WebUserControl.ascx.cs


public partial class WebUserControl : System.Web.UI.UserControl
{
    public delegate void OnButtonClick(string strValue);

    public event OnButtonClick btnHandler;
 
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }

    protected void btnTest_Click(object sender, EventArgs e)
    {
           if (btnHandler != null)
               btnHandler(string.Empty);

           Response.Write("<h3>User Control’s Button Click</h3> <BR /> <BR />");
    }
}

now add new item -> web form -> add
Write the following code in the default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="WUC1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblText" Text="This is On Main Page : " runat="server"></asp:Label>
     
        <asp:DropDownList ID="ddlTemp" runat="server">
            <asp:ListItem>Mahi</asp:ListItem>
            <asp:ListItem>Zoya</asp:ListItem>
            <asp:ListItem>Aditi</asp:ListItem>
        </asp:DropDownList>
     
        <br />
        <br />
        <WUC1:WebUserControl ID="WebUserControl1" runat="server" />
 
    </div>
    </form>
</body>
</html>

save all files and run it in the browser.

Asp.NET User Control

User controls behaves like miniature ASP.Net pages, or web forms, which could be used by many other pages. These are derived from the System.Web.UI.UserControl class.

Here is the example for understanding the user control in asp.NET :-


create a new project.
right click on the project name in solution explorer.
click on add new item.
select Web User Control and add it.

write the following code in the file WebUserControl.ascx


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>

<table>
<tr>
<td align="center"
        style="font-family: 'Arial Black'; font-size: large; font-weight: lighter; font-style: normal; color: #008080"> CEO at CandyFry.</td>
</tr>
<tr>
<td align="center"
        style="font-family: 'Arial Black'; font-size: large; font-weight: lighter; font-style: normal; color: #008080"> Living in Surat,Gujarat. </td>
</tr>
</table>

Then again add new item -> select web form  and add it :-

write the following code in the file Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="~/WebUserControl.ascx" TagName="mahi" TagPrefix="mahi1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>User Control Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server"
         Text="Mahi Babariya" ForeColor="#FF0066"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Info" ForeColor="#993399" />
     
       </div>
       <br />
       <mahi1:mahi ID="footer1" runat="server" />
    </form>
</body>

</html>

save both file and run it in the browser.

Output:-



Monday, March 10, 2014

Asp.NET event: create a simple form

Write below code in the default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" width=300px align=center runat="server" Text="First Name: " 
            style="color: #FF0066"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label2" width=300px align=center runat="server" Text="Last Name: " style="color: #FF0066"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label3" width=300px align=center runat="server" Text="Email ID:" style="color: #FF0066"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label4" width=300px align=center runat="server" Text="Password: " style="color: #FF0066"></asp:Label>
        <asp:TextBox ID="TextBox4" TextMode="Password" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label5" width=300px align=center runat="server" Text="Confirm Password: " 
            style="color: #FF0066"></asp:Label>
        <asp:TextBox ID="TextBox5" TextMode="Password" runat="server"></asp:TextBox>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" align=center runat="server" Text="Button" onclick="Button1_Click" 
            style="color: #FF0066" />
    
        <br />
    
        <br />
        <asp:Label ID="Label7" runat="server" style="color: #FF0066"></asp:Label>
    
        <br />
        <asp:Label ID="Label8" runat="server" style="color: #FF0066"></asp:Label>
        <br />
        <asp:Label ID="Label9" runat="server" style="color: #FF0066"></asp:Label>
    
        <br />
        <asp:Label ID="Label10" runat="server" style="color: #FF0066"></asp:Label>
    
    </div>
    </form>
</body>
</html>

Then view this code in design tab.
Double click on the button.
Default.aspx.cs file will open.
write the following code in it :-

protected void Button1_Click(object sender, EventArgs e)
    {
        Label7.Text = "Your First Name is : "+ TextBox1.Text;
        Label8.Text = "Your Last name is : " + TextBox2.Text;
        Label9.Text = "Your Email id is : " + TextBox3.Text;
        Label10.Text = "Password secret chhe sir";
        Label11.Text = "You are " + DropDownList1.SelectedItem;
    }

CodeBehind in asp.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

as you seen in the above sentence written in the red color is your code behind file.
The only method within this class is the Page_Load, which is called every time the page is loaded.
By default it is look like :-

using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Your First WebSite in asp.NET

Open Visual Studio.
Click New Button in file menu.
Then click on ASP.NET Empty Website


Then right click on the project name in the right side in solution explorer.
Then Click on add new item.

Then click on web form.

You will redirect to the following code :-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

Add following sentence between the <div> </div> tag

"Hello World".

press ctrl+f5 to run the program.