How to save last selection of a Radcombobox into a session

2 posts, 1 answers
  1. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 22 Jan 2014 Link to this post

    Is it possible to save the last selection of a radcombobox into a session , so when the user comes back to this page that the radcombobox is "pre selected" ? 

    What I'm dooing now is this : 
    protected void Page_Load(object sender, EventArgs e)
    if (!this.Page.IsPostBack)
    this.parameterBuId = this.Request["buId"];
    if (string.IsNullOrEmpty(parameterBuId))
     parameterBuId = Session["BusinessUnnitId"].ToString();
    protected void LoadBU(string buId)
        IEnumerable<HtBusinessUnit> businessUnits = null;
        businessUnits = HtBusinessUnit.GetAll();
        this.rcbBusinessUnits.DataTextField = "Name";
        this.rcbBusinessUnits.DataValueField = "BusinessUnitId";
        this.rcbBusinessUnits.DataSource = businessUnits;
        this.rcbBusinessUnits.Items.Insert(0, new RadComboBoxItem("-BU-"));
        if (buId != null && buId != "")
            int index = this.rcbBusinessUnits.Items.IndexOf(this.rcbBusinessUnits.Items.Where(i => i.Value == buId).SingleOrDefault());
            this.rcbBusinessUnits.Items[index].Selected = true;
            this.selectedBu = businessUnits.Where(i => i.BusinessUnitId == int.Parse(buId)).SingleOrDefault();

    Tanks for help and fast answer

  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 22 Jan 2014 Link to this post


    Method 1:

    Please set AutopostBack="true" and in selctedINdexChanged event you can set its value in Session.

    Method 2:

    Radcombobox values changed, By usnig (Jquery) Ajax request you can also set its value in session.

    Note :
    My suggestion is that please use Cookie in place of session. On value changed set the value in cookie (using javascript) and when page load at that time check if the value exists in Cookie then set its value in Radcombobx You can also access cookie in back-end side.

    Jayesh Goyani
  3. DevCraft R3 2016 release webinar banner
Back to Top