Tuesday, July 20, 2010

How to implement a session varable which is available since the first execution cycle - Asp.net

public partial class Test : Page
{
    private string item;
    public string Item
    {
        get
        {
            if (!string.IsNullOrEmpty(item)) return item;
            return (item = (string)(Session["item"] ?? string.Empty));
        }
        set
        {
            Session["Item"] = this.item = value;
        }
    }
 
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.Item = DateTime.Now.ToString("hh:mm:ss");
    }
    protected override void OnLoad(EventArgs e)
    {
        this.Response.Write(this.Item);
    }
}

Other Types:
int? time;
public int Time
{
    get
    {
        if (this.time.HasValue) return time.Value;
        return (time = (int)(Session["time"] ?? 0)).Value;
    }
    set
    {
        Session["time"] = this.time = value;
    }
}
bool? isLive;
public bool IsLive
{
    get
    {
        if (this.isLive.HasValue) return isLive.Value;
        return (isLive = (bool)(Session["isLive"] ?? false)).Value;
    }
    set
    {
        Session["isLive"] = this.isLive = value;
    }
}

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...