Javascript and ASP.Net....Perfect Together???

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Javascript and ASP.Net....Perfect Together???

  1. #1
    KraKheD Guest

    Javascript and ASP.Net....Perfect Together???

    I have a piece of javascript that take items from one listbox to another.

    Everything works fine, HOWEVER, any postback logic that fires does NOT see
    the newly added items.

    The interesting thing is that all of the changes I made in the textboxes
    ARE visible.

    It seems to be the fact that I am adding these items using javascript outside
    of knowledge of ASP.

    Is there a way to FORCE ASP to "see" the newly added items?

    Thanks in advance.

  2. #2
    Ian Drake Guest

    Re: Javascript and ASP.Net....Perfect Together???

    Crack Head,

    The state of the listbox, as ASP.NET knows it, is in the veiwstate hidden
    field on the form. When you add an entry in the listbox through client side
    scripting the state in the viewstate hidden field for the listbox is not
    changed. The next time the form is submitted to the server, the server reconstructs
    the listbox contents from the viewstate field. This is why your addition
    is not there.

    In this situation you could do one of two things:

    1) Do a postback to the server when adding the entry to the listbox. This
    is the intended webform model. The postback is more efficient than most
    think, but I'd only recommend it for intranet apps, or if your audience is
    not dial-up.

    2) Retrieve the values added by the client scripting by using the Request
    object. It's still there and works mostly the same as it did in previous
    versions. You could then add it to the listbox control on the server if

    I think the postback route was MS's intention as the easiest route to take,
    but the reality is that it's not the most efficient way for Internet apps
    to accomplish that set of functionality.

    Ian Drake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center