This is a migrated thread and some comments may be shown as answers.

How to save last selection of a Radcombobox into a session

1 Answer 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nikola
Top achievements
Rank 2
Nikola asked on 22 Jan 2014, 02:41 PM
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();
   }
   this.LoadBU(parameterBuId);
  this.UserGrid.DataBind();
}
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.DataBind();
    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();
     
        this.LoadDE(this.parameterDepId);
    }
}


Tanks for help and fast answer

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Jan 2014, 05:04 AM
Hello,

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.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Nikola
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or