Forum guidelines
AuthorQuestion
asp.net with C#
Posted By meg devi on 14 Oct 2013
hi my name is megala i'm 2nd year IT student  last week i received my question paper from my lecturer it's all  lab exercise.. the question is below :


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


AuthorReply
Re: asp.net with C#
Posted By Sandeep Singh Shekhawat on 14 Oct 2013  
sessiondemo.zip First of all I suggest please read these to article these describe Session in ASP.NET

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/

N
ow 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 Detail</a>

    </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("<br/>");

                }

            }

        }

    }

}

 


on twitter @ss_shekhawat

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.