save page state after post back
-
Dear All, I have two listBox in my webpage which i am adding items from one to other using Javascript works fine like i have source and destination listboxes. i am adding items from source to destination using javascript and source is binded with datasource. after post every thing is cleared from destination listbox. any ideas how to save the state of both listboxes after postback? i enabled page viewstate to true and both listbox view state to true but seems it doesent work and the same i enabled pageviewstate in web.config file no success
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Dear All, I have two listBox in my webpage which i am adding items from one to other using Javascript works fine like i have source and destination listboxes. i am adding items from source to destination using javascript and source is binded with datasource. after post every thing is cleared from destination listbox. any ideas how to save the state of both listboxes after postback? i enabled page viewstate to true and both listbox view state to true but seems it doesent work and the same i enabled pageviewstate in web.config file no success
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
If you are using a button to trigger the postback you could examine the data in each listbox within that event and store the data in some way (Session, ViewState, etc) and repopulate the boxes during the OnLoad event taking into account that this is a PostBack so you might have a method like:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);if (IsPostBack) { // Populate the controls with the data saved on the postback event. } else { // Do the initial databind for the controls. }
}
That should get you started.
me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
-
Dear All, I have two listBox in my webpage which i am adding items from one to other using Javascript works fine like i have source and destination listboxes. i am adding items from source to destination using javascript and source is binded with datasource. after post every thing is cleared from destination listbox. any ideas how to save the state of both listboxes after postback? i enabled page viewstate to true and both listbox view state to true but seems it doesent work and the same i enabled pageviewstate in web.config file no success
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Hey Abdul, Changes done in the client-side using JavaScript will not save it ViewState. To ASP.NET, it doesn't know that you have changed something. To fix this, use a hiddenfield. When you hit the button, get the list of item into the hiddenfield with delimiters. Once the page is back, fill the list with the items with the hiddenfield value. Only HiddenField can maintain states all the times.
Castle Rider
What if I freeze??? Don't forget to breath...
My: Website | Yahoo Group | Blog Spot
-
Hey Abdul, Changes done in the client-side using JavaScript will not save it ViewState. To ASP.NET, it doesn't know that you have changed something. To fix this, use a hiddenfield. When you hit the button, get the list of item into the hiddenfield with delimiters. Once the page is back, fill the list with the items with the hiddenfield value. Only HiddenField can maintain states all the times.
Castle Rider
What if I freeze??? Don't forget to breath...
My: Website | Yahoo Group | Blog Spot
Thanks, HiddenField do save the status, Its really appreciated.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan