How to use Session In

Total Post:341

 914  View(s)
Rate this:
I want to use Session In How to use this Please Help me.
  1. Post:282

    Re: How to use Session In

    Sessions we can be used to store  data for the user specific like cookies.
    sessions will use cookies to store the data.
    Sessions we can used easily in ASP.NET with the Session object. We will re-use the cookie example,
    and use sessions instead. sessions will expire after a certain amount of minutes,as configured in the web.config file.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sesion.aspx.cs" Inherits="Forumasp.Sesion" %>

    <!DOCTYPE html>
    <html xmlns="">
    <head id="Head1" runat="server">

    <body runat="server" id="Body">
        <form id="form1" runat="server">
                Change Body Color:
                <asp:DropDownList runat="server" ID="color" AutoPostBack="True" OnSelectedIndexChanged="color_IndexChanged" Width="200">
                    <asp:ListItem Value="black" Selected="True">black</asp:ListItem>
                    <asp:ListItem Value="Blue">Blue</asp:ListItem>
                    <asp:ListItem Value="Red">Red</asp:ListItem>
                    <asp:ListItem Value="green">green</asp:ListItem>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace Forumasp
        public partial class Sesion : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                if (Session["BackgroundColor"] != null)
                    color.SelectedValue = Session["BackgroundColor"].ToString();
                    Body.Style["background-color"] = color.SelectedValue;

            protected void color_IndexChanged(object sender, EventArgs e)
                Body.Style["background-color"] = color.SelectedValue;
                Session["BackgroundColor"] = color.SelectedValue;


      Modified On Apr-11-2018 12:25:49 AM