1

I have got a radio button list and based on selection of the radio button list , the drop-downs will populate. Important thing is here the radiobutton list is set to autopostback=true.

And also when i move to next page by button click, And when i come back. Drop down button not able to maintain state. It is losing values. It is important for me to maintain state until i reach the last page. How can i approach this problem. I have used sessions but was not successful. Could you tell me how to implement sessions.

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
  • This is because of your page life cycle, most likely. Check out [this SO question and answer](http://stackoverflow.com/questions/4189158/asp-net-dropdownlist-not-retaining-selected-item-on-postback). – Icemanind Apr 29 '14 at 04:09
  • please add your code here to know more..about the scenario! – SHEKHAR SHETE Apr 29 '14 at 04:18

3 Answers3

0

If you want to use sessions, you could check the session variable with all of the values of the list

if(Session["selectedList"] != Null){
    var check = Session["selectedList"].ToString();
    foreach(ListItem item in yourList.Items){
        if(item.Value.Equals(check))
            // set it as selected
    }
}

For storing, when you click the button

Session["selectedList"] = yourList.SelectedValue;

You could also use the indexes instead of the values. You can also create a session variable for each dropdown/radiobuttonlist and you just make a loop for each.

UPDATE

Thanks to Shekhar for pointing this out. You need to go through all of the lists that you want to store and save them with these loops, not just the dropdowns. Then, you need to restore the radio button values, rebind the dropdowns, and then set the selected item for each.

Newyork167
  • 494
  • 5
  • 9
0

hi @Newyork167 this will not work as he mentioned above that "based on selection of the radio button list , the drop-downs will populate." so you have to store the "RadioButtonList" Selected value and accordingly fillDropDownlist Values and set selected after returning back to the page.

SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
0

Ok. As per my understanding you need to save a page state so that when you come back then you get the page in previous state where you left. So to do this you have two ways. 1. Before jumping to next page, store everything in session like "Radiobutton selected value", dropdown selected value and other settings if any. 2. Pass these values "Radiobutton selected value", "dropdown selected value" and other if any as the query string and when you coming back then read the same query string. In either way when you will come back then you will have the previous data. In the page_load event, just check whether you have that data or not. If yes then populate your controls with previous data else populate your controls for first load. Here is some link for your reference. http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString Passing Session[] and Request[] to Methods in C#

Community
  • 1
  • 1
Amnesh Goel
  • 2,617
  • 3
  • 28
  • 47