Implement the following
changes:
Your webpage application will allow the user to enter the
details for any number of people on
one page and another page (Use the About) should display the details.
Hint 1: To achieve this use a generic list or an array list to
hold the instances of the person objects that you are creating by clicking the
button and use a session to store the
list. Don't forget about boxing and unboxing.
Hint 2 : You can use a
listbox on the About page and you can add elements through the Items property
For example: ListBox1.Items.Add(inputString )
i dont know how to create this part ...pls help me
Sandeep Singh ShekhawatPosted Oct 14, 2013, 9:55 PM
http://www.c-sharpcorner.com/UploadFile/3d39b4/introduction-to-Asp-Net-session/
http://www.c-sharpcorner.com/UploadFile/3d39b4/inproc-session-state-mode-in-Asp-Net/
Now download complete source code for application that solve your scenario and i write steps here for...
Step 1. Create a class Person
namespace SessionDemo
{
public class Person
{
private string mName = string.Empty;
private string mEmail = string.Empty;
public Person(string name, string email)
{
mName = name;
mEmail = email;
}
public string Name
{
get { return mName; }
}
public string Email
{
get { return mEmail; }
}
//can define more properties
}
}
Step 2 Create UI for Person information input
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonInfo.aspx.cs" Inherits="SessionDemo.PersonInfo" %>
DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>title>
head>
<body>
<form id="form1" runat="server">
<div>
Name: <asp:TextBox ID="txtName" runat="server">asp:TextBox><br />
Email: <asp:TextBox ID="txtEmail" runat="server">asp:TextBox><br />
<asp:Button ID="btnSubmit" runat="server" Text="Add" OnClick="btnSubmit_Click" />
<a href="About.aspx">Show Detaila>
div>
form>
body>
html>
3. Code behind to store person data
using System;
using System.Collections.Generic;
namespace SessionDemo
{
public partial class PersonInfo : System.Web.UI.Page
{
public static IList<Person> personList = new List<Person>();
protected void btnSubmit_Click(object sender, EventArgs e)
{
personList.Add(new Person(txtName.Text, txtEmail.Text));
Session["PersonList"] = personList;
}
}
}
4. show person on about page
using System;
using System.Collections.Generic;
namespace SessionDemo
{
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["PersonList"] != null)
{
IList<Person> personList = (List<Person>)Session["PersonList"];
foreach (Person objPerson in personList)
{
Response.Write(string.Format("Name :{0} and Email :{1}", objPerson.Name, objPerson.Email));
Response.Write("
");
}
}
}
}
}