1. Write a Program to Print “Hello Computer” On Web Form.
<form id="form1" runat="server">
        <div>
            <%Response.Write( "Hello Computer"); %>
        </div>
    </form>

2. Write a Program Using Different Namespaces.

using System;
namespace MyProgram
{
    public class MyClass
    {
        public static void Main()
        {
            MyNamespace.SampleClass.myMethod();
        }
    }
}


namespace MyNamespace
{
    public class SampleClass
    {
        public static void myMethod()
        {
            Console.WriteLine("Creating my namespace");
        }
    }
}

3. Write a Program To Set a Link For New Page.

Step 1 – Open the Visual Studio –> Create a new empty Web application.
Step 2 – Create two New web page one for display hyperlink and other for navigate to it.
Step 3 – Drag and drop HyperLink control on web page from Toolbox.
Step 4 – Set Text property of Hyperlink Control
Step 5 – Set NavigateUrl Property to destination web page name.


    <form id="form1" runat="server">
        <div>
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/SamplePage2.aspx">Navigate to Second Page</asp:HyperLink>
            </div>
    </form>

4. Write a Program to Demonstrate Request, Response and Server Object.

<form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
    </form>

The code behind Button1_Click:


 protected void Button1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(TextBox1.Text))
        {
            // Access the HttpServerUtility methods through
            // the intrinsic Server object.
            Label1.Text = "Welcome, " + Server.HtmlEncode(TextBox1.Text) + ". <br/> The url is " + Server.UrlEncode(Request.Url.ToString());
   }
    }

5. Write a Program using which addition and substraction of two Interger value Possible.

using System;
public delegate int MyDelegate(int a, int b); //declaring a delegate
class Program
{
    static void Main(string[] args)
    {
        MyDelegate addDelegate = Calculation.add;
        Console.WriteLine(addDelegate(5, 2));

        MyDelegate subDelegate = Calculation.sub;
        Console.WriteLine(subDelegate(5, 2));
    }
}

 class Calculation
{
   public static int add(int n1, int n2)
    {
        return n1 + n2;
    }
    public static int sub(int a, int b)
    {
        return a - b;
    }
}

6. Write a program using while or for loop to print sum of first 100 ODD and Even Numbers.

using System;
namespace SumOfOdd_Even
{
    class Program
    {
        static void Main(string[] args)
        {
	     // Calling Functions..
            sumOfOdd();
            sumOfEven();
        }
        // Function for Sum of First 100 Odd Integers.
        static void sumOfOdd()
        {
            int num = 100, count = 1, sum = 0;
            while (count <= num)
            {
                if (count % 2 != 0)
                {
                    sum = sum + count;
                }
                count++;
            }
            Console.WriteLine("Sum of ODD integer number is " + sum);
        }
        // Function for Sum of First 100 Even Integers.
        static void sumOfEven(){
            int num = 100, count = 1, sum = 0;
            while (count <= num){
                if (count % 2 == 0){
                    sum = sum + count;
                }
                count++;
            }
            Console.WriteLine("Sum of Even integer number is " + sum);
        }
    }
}

7. Write a program using Foreach loop.

using System;
namespace Basics
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Avengers = { "Thor", "Hulk", "Ironman", "Natasha" };
            foreach (string i in Avengers)
            {
                Console.WriteLine(i);
            }
        }
    }
}

8. Write a program to Create Simple Web Application using two or more web form.

Web-Form-1.aspx
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/WebForm2.aspx">Go to Web Form 2</asp:HyperLink>
            <br/>
            <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/WebForm3.aspx">Go to Web Form 3</asp:HyperLink>
      
Web-Form-2.aspx
        <div>
            <h1> Web Form 2 </h1>
        </div>

Web-Form-3.aspx
        <div>
            <h1> Web Form 2 </h1>
        </div>

9. Write a program to demonstrate different Common Control.


    <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Simple Web Forms"></asp:Label> <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br/>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>
    </form>

10. Write a program to add the value of Text Box in to Dropdown List and List box Controls.

<form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>Value 1</asp:ListItem>
                <asp:ListItem>Value 2</asp:ListItem>
                <asp:ListItem>Value 3</asp:ListItem>
            </asp:DropDownList>
            <br />
            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem>List Item 1</asp:ListItem>
                <asp:ListItem>List Item 2</asp:ListItem>
                <asp:ListItem>List Item 3</asp:ListItem>
            </asp:ListBox>
        </div>
    </form>

11. Write a program to Delete Items from Dropdown list and List box.

<form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>Item 1</asp:ListItem>
                <asp:ListItem>Item 2</asp:ListItem>
                <asp:ListItem>Item 3</asp:ListItem>
            </asp:DropDownList>
            <br />
            <asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="Button" />
            <br />
            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem>Item 1</asp:ListItem>
                <asp:ListItem>Item 2</asp:ListItem>
                <asp:ListItem>Item 3</asp:ListItem>
            </asp:ListBox>
            <br />
            <asp:Button ID="Button1" runat="server" OnClick="Button2_Click" Text="Delete Item" />
        </div>
    </form>

Code-Behind :
protected void Button1_Click(object sender, EventArgs e)
    {
DropDownList1.Items.RemoveAt(DropDownList1.Items.IndexOf(DropDownList1.SelectedItem));
    }
   protected void Button2_Click(object sender, EventArgs e)
    {
        ListBox1.Items.RemoveAt(ListBox1.Items.IndexOf(ListBox1.SelectedItem));
    }

12. Write a program to set Image on Image Control according to selection of image name from dropdown list.

Web-Form :
<form id="form1" runat="server">
        <div>
           <asp:DropDownList ID="ddlImages" runat="server" AppendDataBoundItems="true" AutoPostBack = "true" OnSelectedIndexChanged = "FetchImage">
    <asp:ListItem Text="Select Image" Value="0" />
               <asp:ListItem Value="1">Image 1</asp:ListItem>
               <asp:ListItem Value="2">Image 2</asp:ListItem>
               <asp:ListItem Value="3">Image 3</asp:ListItem>
</asp:DropDownList>
<hr />
<asp:Image ID="Image1" runat="server" Visible = "false"/>
        </div>
    </form>
Code-Behind :
protected void FetchImage(object sender, EventArgs e)
    {
        string id = ddlImages.SelectedItem.Value;
        Image1.Visible = id != "0";
        if (id == "1")
        {
            Image1.ImageUrl = "images/image1.png";
        }
        if (id == "2")
        {
            Image1.ImageUrl = "images/image2.jpg";
        }
        if (id == "3")
        {
            Image1.ImageUrl = "images/image3.png";
        }
    }

13. Write a program which demonstrate the Validation Control.

 <form id="form1" runat="server">
        <div>
            Username : <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Username is Requied" ForeColor="#FF3300">*</asp:RequiredFieldValidator>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </div>
    </form>

14. Write a program which is use different Rich Control.


  <form id="form1" runat="server">
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <br />
            <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
            <br />
            <asp:MultiView ID="MultiView1" runat="server">
            </asp:MultiView>
        </div>
    </form>

15. Write a program using Menu Control.


 <form id="form1" runat="server">
        <div>
            <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
                <Items>
                    <asp:MenuItem NavigateUrl="~/About.aspx" Text="About Us" Value="About Us"></asp:MenuItem>
                    <asp:MenuItem NavigateUrl="~/Contact.aspx" Text="Contact Us" Value="Contact Us"></asp:MenuItem>
                </Items>
            </asp:Menu>
        </div>
    </form>

16. Write a program using TreeView Control.

<form id="form1" runat="server">
        <div>
            <asp:TreeView ID="TreeView1" runat="server">
                <Nodes>
                    <asp:TreeNode Text="Parent1" Value="Parent1">
                        <asp:TreeNode Text="Child 1" Value="Child 1"></asp:TreeNode>
                        <asp:TreeNode Text="Child 2" Value="Child 2"></asp:TreeNode>
                    </asp:TreeNode>
                    <asp:TreeNode Text="Parent 2" Value="Parent 2">
                        <asp:TreeNode Text="Child 1" Value="Child 1"></asp:TreeNode>
                        <asp:TreeNode Text="Child 2" Value="Child 2"></asp:TreeNode>
                    </asp:TreeNode>
                </Nodes>
            </asp:TreeView>
        </div>
    </form>

17. Write a program using Sitemap Control.

Step 1: Add two web forms to the application named myweb1.aspx and myweb2.aspx by performing the following steps:
Move to the Solution Explorer window
Right-click on the application name and select the Add New Item option from the context menu
Name the web form as myweb1.aspx and click the Add button

Step 2: Similarly add the myweb2.aspx web form to the application. After that we have to add the Site Map file into the project. The Site Map file is the XML file and has the extension .sitemap. The steps are as follows.

Step 3: Right-click the application in the Solution Explorer window and then click the Add New Item option from the context menu.
Step 4: Select the Site Map Template from the Templates Pane. Note that, by default, the file has the name web.sitemap.


  <siteMapNode url="Default.aspx" title="myhomepage"  description="">
    <siteMapNode url="myweb1.aspx" title="myfirstpage"  description="" />
    <siteMapNode url="myweb2.aspx" title="mysecondpage"  description="" />
  </siteMapNode>

Step 5: Now Add one SiteMapPath control on the Default.aspx page from the navigation tab of the toolbox.
Step 6: Add two hyperlink controls from the toolbox to the Default.aspx page and set the text property of the control.
Step 7: Now set the NavigateUrl property of the first hyperlink control and select the myweb1.aspx file as follows.
Step 8: Now set the NavigateUrl Property of second hyperlink control and select myweb2.aspx file.
Step 9: Now Add one SiteMapPath control on the myweb1.aspx & myweb2.aspx page from the navigation tab of the toolbox.

18. Write a program to demonstrate use of Master Page and Theme.

Master Page :-
Step 1 : Create a new project using “File” -> “New” -> “Project…” then select web “ASP.NET Web Forms Application”. Name it “MasterPageDemo“.
Step 2 : Go to Solution Explorer then right-click on your application then select “Add New Item” then select “Master Page” and name it “Site.Master”.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
     <style type="text/css">
        html, body
        {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            background-color:burlywood;
        }
    </style>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div class="top">
        <h1 style="text-align: center;">
            www.aspforums.net</h1>
        <br />
    </div>
    <div class="left">
        <ul>
            <li style="margin-top: 0px"><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
            <li><a href="#">FAQ</a></li>
            <li><a href="#">News</a></li>
        </ul>
    </div>
    <div class="right">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Step 3 : Now, go to Solution Explorer then right-click on your application then select “Add New Item” then select “Web form using Master Page” and name it “Home.aspx”. Next add click.
Step 4 : Now, select a Master Page; just click “OK”.
Theme :
Step 1 : Go to Solution Explorer then right-click on your application then select “Add New Item” then select “Skin File and add this.

<asp:TextBox  runat="server" BackColor="#FF0066"></asp:TextBox>
   <asp:Button runat="server" Text="Button" BackColor="#FF6600" />

Step 2 : Add New Web Form and Add this this.

<%@ Page Language="C#" AutoEventWireup="true" StylesheetTheme="SkinFile" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>  
    <form id="form1" runat="server">  
    <div>  
        <asp:TextBox ID="TextBox1" runat="server" BackColor="#FF0066"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" BackColor="#FF6600" />
      </div>  
    </form>  
</body>
</html>

19. Write a program to display data into GridView control.


<form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
                </Columns>
            </asp:GridView>
            <br />
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Name], [City], [Gender] FROM [mytable]"></asp:SqlDataSource>
        </div>
    </form>

20. Write a program for display data into DetailView Control.

<form id="form1" runat="server">
        <div>
            <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="192px" AutoGenerateRows="False" DataSourceID="SqlDataSource1">
                <Fields>
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
                </Fields>
            </asp:DetailsView>
s            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Name], [City], [Gender] FROM [mytable]"></asp:SqlDataSource>
        </div>
    </form>

21. Write a program to perform insert and update operation in Database.

Code-Behind :
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
      conn.Open();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "insert into tbl_user (Name, Email, Contact) values('"+ txtName.Text + "',  '"+ txtEmail.Text + "', '"+ txtContact.Text + "')";
        cmd.Connection = conn;
        cmd.ExecuteNonQuery();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "UPDATE tbl_user SET Name='" + txtName.Text + "', Email='" + txtEmail.Text + "', Contact='" + txtContact.Text + "' WHERE Name='"+txtName.Text+"'";
        cmd.Connection = conn;
        cmd.ExecuteNonQuery();
    }
}

22. Write a program to perform delete and search operation in Database.

<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="Delete" />
Code-Behind btnDelete:
 protected void btnDelete_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = db.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "DELETE FROM tbl_user WHERE Name='"+txtName.Text+"' ";
        cmd.Connection = db;
        cmd.ExecuteNonQuery();
    }

23. Write a program to display the records from database using Data Reader Object.

//

24. Write a program to demonstrate the various methods of Dataset Object.

//