any changes (by javascript) turn back after postback
-
Hi All I develop a dual list box server control. it using aspx listbox and javascript to move itemlist from one listbox to another, but after postback listbox items turn back :confused: I can't find where is the problem. Sorry for my bad inglish
i think that in your code behiend or the .aspx file you are filling the Listboxes each time you postback, try to use IsPostBack to fill the Listbox only the first time and not on each postback like this: if ( !IsPostBack ) { fillListBox ( ) ; } if this didn't work post your code.
-
i think that in your code behiend or the .aspx file you are filling the Listboxes each time you postback, try to use IsPostBack to fill the Listbox only the first time and not on each postback like this: if ( !IsPostBack ) { fillListBox ( ) ; } if this didn't work post your code.
-
If you have ViewState enabled for the listboxes, then any changes that you make using client script are being overwritten when the ViewState is restored. Sadly, even if you disable ViewState, your client changes will not be automatically reflected. What you could do is to use some client script to force selection of all items in the listbox before the postback is performed. By doing so, all of your client changes will be availible in the post data. The drawback to this method is that you'll have to scrape the
Request.Params
collection and recreate your items manually, rather then relying on ViewState. A bit of a hack, but it works. Hope that helps. :) --Jesse -
If you have ViewState enabled for the listboxes, then any changes that you make using client script are being overwritten when the ViewState is restored. Sadly, even if you disable ViewState, your client changes will not be automatically reflected. What you could do is to use some client script to force selection of all items in the listbox before the postback is performed. By doing so, all of your client changes will be availible in the post data. The drawback to this method is that you'll have to scrape the
Request.Params
collection and recreate your items manually, rather then relying on ViewState. A bit of a hack, but it works. Hope that helps. :) --Jesse -
Thanks for your help, There is nothing in post data related to my component :omg: listbox name is not in Request.Params.AllKeys I think there is a little mistake that I can't see it :sigh:
In order to scrape the post data, you'll need to use the
UniqueID
of the listbox, not the name. As such, you'll need to be sure that the listbox and all of its containters have the sameID
and are placed onto the page. Failure to do so will cause theUniqueID
to be different. The syntax would look similar to:string val = Request.Params[myListbox.UniqueID];
Also, you won't see the items in your listbox if they aren't selected. As I mentioned above, I'd recommend using some client script to force all listbox items to be selected when posting back. Hope that helps. :) --Jesse -
Hi there, In addition to Jesse's suggestion, you can use a hidden element to store the state of each list. Basically, after adding/removing items, the state of the two lists will be persisted, then at the server side the list controls can be initialized based on the hidden elements, this action can be placed in the OnInit event of your custom control.
-
Hi All I develop a dual list box server control. it using aspx listbox and javascript to move itemlist from one listbox to another, but after postback listbox items turn back :confused: I can't find where is the problem. Sorry for my bad inglish