Friday, January 19, 2024

ASP.NET properties with viewstate and session of List - Viewstate property

  public List<CourtApplicationProceedingsDTO> ProceedingList

        {

            get { return (Session["CourtApplicationProceedings"] != null ? (List<CourtApplicationProceedingsDTO>)Session["CourtApplicationProceedings"] : new List<CourtApplicationProceedingsDTO>()); }

            set { Session["CourtApplicationProceedings"] = value; }

        }


        public long DatesId

        {

            get { return Convert.ToInt64(ViewState["DatesId"]); }

            set { ViewState["DatesId"] = value; }

        }


//For string

public String Text

{

    get 

    { 

        object o = ViewState["Text"]; 

        return (o == null)? String.Empty : (string)o;

    }


    set

    {

        ViewState["Text"] = value;

    }

}

// Int property

public int SomeInteger

{

    get

    {

        object o = ViewState["SomeInteger"];

        if (o != null) return (int)o;

        return 0;

        //a default

    }

    set { ViewState["SomeInteger"] = value; }

}


reference:- https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.viewstate?view=netframework-4.8.1


https://www.karpach.com/asp-net/property-in-viewstate/

No comments:

Post a Comment