Sandhurst
Sandhurst

Reputation:

Accessing ListBox values at Server after modifying it via Javascript ASP.Net

I have a listBox whose values I am manipulating by javascript for e.g adding a new Item to list. Now when I am trying to access this listBox from Server its only showing me the values that were originally part of ListBox at PageLoad. The newly added items are not accessible.

How can I access those new added Items at server

Upvotes: 1

Views: 1542

Answers (2)

Andrew Hare
Andrew Hare

Reputation: 351566

I would look at where you are populating the list and see if you populate it each page load or only if !Page.IsPostBack. If you load the contents of the list on each page load you will wipe out any changes from the client with the original data.

You are going to want to do something like this:

if (!Page.IsPostBack)
{
    // load your list up
}

This means that on subsequent postbacks your list will not be refreshed from your datasource and will not overwrite any client changes.

Upvotes: 0

Henk
Henk

Reputation: 704

You need to use Request.Params["YourListBoxID'] to read the added values.

Upvotes: 3

Related Questions