Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
// 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 )
      if(session["sessionName"]!=null)
{
  DataTable dt=new DataTable();
dt=session["sessionName"] as DataTable;
}

}

I hope this will help u.
 
Share this answer
 
Comments
Dhritirao's 17-Jan-13 2:40am    
thanku
solanki.net 17-Jan-13 3:32am    
Your welcome
Dhritirao's 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
solanki.net 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 ?
Dhritirao's 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
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 .
 
Share this answer
 
Comments
Dhritirao's 17-Jan-13 5:13am    
can u tell me how to bind
solanki.net 17-Jan-13 5:21am    
show me your code
Dhritirao's 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
Dhritirao's 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
u should not use these much of session .this is not right way of coding standard . send me first page code also .
 
Share this answer
 
C#
 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));
        dt.Rows.Add(FirstName.Text.Trim(),LastName.Text.Trim(),Password.Text.Trim(),Email.Text.Trim(),Phone.Text.Trim(),Convert.ToInt32(Phone.Text));
        Session["dt"] =dt;
 Response.Redirect("AddInfo.aspx");
        
 }

// 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();
                  dt=session["dt"];
                  // here bind your controls .
                   // for example
                  // txtFirstName= dt.Rows[0][0];
                 // txtLastName=dt.Rows[0][1]; according to table column bind your controls . 
 
     

           }

I HOPE THIS WILL HELP U . FIRST TIME I WROTE THIS MUCH CODE FOR SOME ONE HAHA.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900