Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. any changes (by javascript) turn back after postback

any changes (by javascript) turn back after postback

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadminhelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    w3Nima
    wrote on last edited by
    #1

    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

    H W 2 Replies Last reply
    0
    • W w3Nima

      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

      H Offline
      H Offline
      Hercules01
      wrote on last edited by
      #2

      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.

      W 1 Reply Last reply
      0
      • H Hercules01

        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.

        W Offline
        W Offline
        w3Nima
        wrote on last edited by
        #3

        I do it. but it dos not work.

        J M 2 Replies Last reply
        0
        • W w3Nima

          I do it. but it dos not work.

          J Offline
          J Offline
          Jesse Squire
          wrote on last edited by
          #4

          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

          W 1 Reply Last reply
          0
          • J Jesse Squire

            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

            W Offline
            W Offline
            w3Nima
            wrote on last edited by
            #5

            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:

            J 1 Reply Last reply
            0
            • W w3Nima

              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:

              J Offline
              J Offline
              Jesse Squire
              wrote on last edited by
              #6

              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 same ID and are placed onto the page. Failure to do so will cause the UniqueID 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

              1 Reply Last reply
              0
              • W w3Nima

                I do it. but it dos not work.

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • W w3Nima

                  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

                  W Offline
                  W Offline
                  w3Nima
                  wrote on last edited by
                  #8

                  I Correct the code, So thanks for your valuable information :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups