Client Access List Items Added

  • I have a list with runat = server
    1. Items are added to this list on the client side using javascript
    2. I would like to get server side items at the click of a button

The problem is the server side click handler, I do not see new items added to the list. Only those items that were on the load_page are displayed. How to do what I want to do

Change 1

My code is like this

 protected void Page_Load(object sender, EventArgs e)
    {


        if (!IsPostBack)
        {
            if (ViewState["gameID"] == null)
            {
                //Populate Listbox
                //Set gameid in viewstate
            }

            //Add javascript handlers to buttons
            btnSomeButton.Attributes.Add("onclick", "aJavaScriptFunction"); 

        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        ListItemCollection x = ListBoxRanks.Items;
        //Here items is has just those items that are added to the listbox on page load

    }
+3
source share
3 answers

And when the leek abstraction :)

- , .

viewstate. - ajax serveride.

+4

ListBox, Page.IsPostBack - false. , .

, , ASP.NET . , , , , .

0

You must use ajax to add items to the drop-down list. This ensures that your viewstate is in sync with the serveride drop down menu.

0
source

Source: https://habr.com/ru/post/1707855/


All Articles