Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
here in page 1 i need to enter the details of employee and entering the details these should be stored in a session and in page2 the details what i have entered should display with help of session and later i need to submit how toproceed. how to write the code for session in page load
Posted 16-Jan-13 20:30pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

// suppose u want to store data table in session .
session["sessionName"]=dt;// your table .
protected void Page_Load(object sender, EventArgs e)
// now u want to access that session here(on other page )
  DataTable dt=new DataTable();
dt=session["sessionName"] as DataTable;
I hope this will help u.
Angelina Feb21 at 17-Jan-13 2:40am
thanku at 17-Jan-13 3:32am
Your welcome
Angelina Feb21 at 17-Jan-13 3:36am
one more if we want to see the page 1 values if we click prev button in page 2 how it can be possible at 17-Jan-13 3:41am
can u explain more ? if u click prev button then what r u doing i mean redirecting to first page or what ?
Angelina Feb21 at 17-Jan-13 4:26am
ya i need to redirect to the first page and the data which i entered in first page should be there. but im getting empty fields while redirecting to first page
Nandakishorerao at 17-Jan-13 4:39am
when you are redirecting to the second page keep a temporary intermediate session value.. session["temp"]=session["your session from previous page"]; and do your operations later while redirecting back use this temp session to load to session["your session from previous page"] and later capture it in first page
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

of course u will get empty fields cause page is post back so after entering record in fields u should store records in session that u already doing (i think) .on second page u r getting first page value by session(that i already told ) that session u should use for binding the first page controls when u click on prev button .
Angelina Feb21 at 17-Jan-13 5:13am
can u tell me how to bind at 17-Jan-13 5:21am
show me your code
Angelina Feb21 at 17-Jan-13 6:36am
public partial class AddInfo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { FirstName.Text = Session["FirstName"].ToString(); LastName.Text = Session["LastName"].ToString(); Email.Text = Session["Email"].ToString(); Phone.Text = Session["Phone"].ToString(); } protected void btnsubmit_Click(object sender, EventArgs e) { addinfo obj = new addinfo(); obj.FirstName = Session["FirstName"].ToString(); obj.LastName = Session["LastName"].ToString(); obj.Email = Session["Email"].ToString(); obj.Phone = Convert.ToInt32(Session["Phone"].ToString()); obj.TaxTerms = rbtaxterms.SelectedItem.Text.Trim(); obj.PrimarySkill = primaryskill.Text.Trim(); obj.SecondarySkill = secondaryskill.Text.Trim(); obj.ResourceManager = resourcemanager.Text.Trim(); obj.Customer=customer.Text.Trim(); obj.StartDate=Convert.ToDateTime(startdate.Text); obj.Password = Session["Password"].ToString(); obj.Role = Session["Role"].ToString(); Adodata objadodata = new Adodata(); objadodata.userdetails(obj); } protected void btnprev_Click(object sender, EventArgs e) { Response.Redirect("UserInfo.aspx"); } } this is my second page code in that prev button i need to write the code
Angelina Feb21 at 17-Jan-13 7:12am
public partial class UserInfo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bindDropDownList(); } } protected void bindDropDownList() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("Select ID,Role FROM RoleID", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); ddlrole.DataSource = ds; ddlrole.DataTextField = "Role"; ddlrole.DataValueField = "ID"; ddlrole.DataBind(); ddlrole.Items.Insert(0, new ListItem("--Select--", "0")); con.Close(); } protected void btnNext_Click(object sender, EventArgs e) { Session["FirstName"] = FirstName.Text.Trim(); Session["LastName"] = LastName.Text.Trim(); Session["Password"] = Password.Text.Trim(); Session["Email"] = Email.Text.Trim(); Session["Phone"] = Phone.Text.Trim(); Session["Role"] = Convert.ToInt32(Phone.Text); Response.Redirect("AddInfo.aspx"); } } this first page code
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

u should not use these much of session .this is not right way of coding standard . send me first page code also .
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

 protected void btnNext_Click(object sender, EventArgs e)
// Instead of using multiple session do like this (on your first page )
   DataTable dt = new DataTable();
        dt.Columns.Add("FirstName", typeof(string));
        dt.Columns.Add("LastName", typeof(string));
        dt.Columns.Add("Password", typeof(string));
        dt.Columns.Add("Email", typeof(string));
        dt.Columns.Add("Phone", typeof(string));
        dt.Columns.Add("Role", typeof(Int32));
        Session["dt"] =dt;
// now from second page 
 protected void btnprev_Click(object sender, EventArgs e)
     Response.Redirect("UserInfo.aspx?Value=secondPage");// this will redirect to page first with query string .

//now  on page load of first page 
if (Request.QueryString["value"] != null)
                DataTable dt=new DataTable();
                  // here bind your controls .
                   // for example
                  // txtFirstName= dt.Rows[0][0];
                 // txtLastName=dt.Rows[0][1]; according to table column bind your controls . 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Shai Vashdi 1,518
1 OriginalGriff 503
2 Manas Bhardwaj 393
3 Tadit Dash 310
4 Damith Weerasinghe 290
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 5,856
2 Peter Leow 4,405
3 Maciej Los 3,540
4 Abhinav S 3,513

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid