How to transfer values from one page to another page using Sessions

Hi friends,By using Sesions we can store the values and we can transfer the values from page to another page.

In this i would like to explain how to transfer registration form details from one page to another page.


First,Open the Registration.aspx.cs page and write the following code  in page load

protected void Page_Load(object sender, EventArgs e)
{
    Session["txt1"] = txt_uname.Text;
        Session["txt2"] = txt_pwd.Text;
        Session["cpwd"] = txt_cpwd.Text;
        Session["txt3"] = txt_age.Text;
        Session["txt4"] = txt_email.Text;
        Session["txt5"] = genderRadioButton.SelectedItem.ToString();
        Session["txt6"] = txt_mobile.Text;
        Session["txt7"] = txt_date.Text;
        Session["txt8"] = ddlCountry.SelectedItem.ToString();
        Session["txt9"] = ddlState.SelectedItem.ToString();
}


next,In which page you would like to display the Details of the Registration form..if you would like to display the values in Display.aspx page.just copy the code in the Page load
 protected void Page_Load(object sender, EventArgs e)
    {
        //for session using
        lbl_duname.Text = (string)Session["txt1"];
        lbl_dpwd.Text = (string)Session["txt2"];
        lbl_dage.Text = (string)Session["txt3"];
        lbl_demail.Text = (string)Session["txt4"];
        lbl_dgender.Text = (string)Session["txt5"];
        lbl_dmobile.Text = (string)Session["txt6"];
        lbl_ddate.Text = (string)Session["txt7"];
        lbl_dcountry.Text = (string)Session["txt8"];
        lbl_dstate.Text = (string)Session["txt9"];
       
    }
That's it...Happy Coding Friends

developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Facebook Rss Twitter

Get Weekly News letter of Updates!