0% found this document useful (0 votes)
79 views

Write A Program in ASP

This document describes programs in ASP.Net using VB.Net or C# to: 1. Allow a user to add and remove student names from a list box control. 2. Maintain a user session by storing an email address in a session variable if the user logs in with the correct password, and displaying the stored email. 3. The output shows the stored session value.

Uploaded by

Chetan Kannake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Write A Program in ASP

This document describes programs in ASP.Net using VB.Net or C# to: 1. Allow a user to add and remove student names from a list box control. 2. Maintain a user session by storing an email address in a session variable if the user logs in with the correct password, and displaying the stored email. 3. The output shows the stored session value.

Uploaded by

Chetan Kannake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Write a program in ASP.Net using VB.

Net or C# that take a student


name from the user, add that name to list-box control and delete the
chosen name from the list box.

.aspx Code  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inher
its="Default2" %>
 
<!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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        &nbsp;
        <asp:Button ID="Button1" runat="server" style="background-color:Red"
            OnClick="Button1_Click" Text="Add" Width="99px" />
        &nbsp;
        <br />
        <br />
        <asp:ListBox ID="ListBox1" runat="server" style="background-color:Orange"  
Width="255px"></asp:ListBox>
        <asp:Button ID="Button2" runat="server" style="background-color:Red" 
            Text="Delete" Width="134px" onclick="Button2_Click" />
    </div>
    </form>
</body>
</html>

Code-behind
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Add(TextBox1.Text);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ListBox1.Items.RemoveAt(ListBox1.Items.IndexOf(ListBox1.SelectedItem));
    }
}

OUTPUT:-

Add Student name:

Delete Student name:


2. Write a program in ASP.Net using VB.Net or C# for maintaining session

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind=
"Default.aspx.cs"  
Inherits="SessionExample._Default" %>  
<head>  
    <style type="text/css">  
        .auto-style1 {  
            width: 100%;  
        }  
        .auto-style2 {  
            width: 105px;  
        }  
    </style>  
</head>  
<form id="form1" runat="server">  
    <p>Provide Following Details</p>  
    <table class="auto-style1">  
        <tr>  
            <td class="auto-style2">Email</td>  
            <td>  
                <asp:TextBox ID="email" runat="server" TextMode="Email"></asp:TextBox
>  
            </td>  
        </tr>  
        <tr>  
            <td class="auto-style2">Password</td>  
            <td>  
                <asp:TextBox ID="password" runat="server" TextMode="Password"></asp:T
extBox>  
            </td>  
        </tr>  
        <tr>  
            <td class="auto-style2"> </td>  
            <td>  
                <asp:Button ID="login" runat="server" Text="Login" OnClick="login_Click" 
/>  
            </td>  
        </tr>  
    </table>  
    <br />  
    <asp:Label ID="Label3" runat="server"></asp:Label>  
    <br />  
    <asp:Label ID="Label4" runat="server"></asp:Label>  
</form>

Behind code:
using System;  
using System.Web.UI;  
namespace SessionExample  
{  
    public partial class _Default : Page  
    {  
        protected void login_Click(object sender, EventArgs e)  
        {  
            if (password.Text=="qwe123")  
            {  
                // Storing email to Session variable  
                Session["email"] = email.Text;  
            }  
            // Checking Session variable is not empty  
            if (Session["email"] != null)  
            {  
                // Displaying stored email  
                Label3.Text = "This email is stored to the session.";  
                Label4.Text = Session["email"].ToString();  
            }  
        }  
    }  
}  

OUTPUT:-
stored session value

3.

You might also like