views:

38

answers:

1

Im currently trying to use a jQuery plugin: jQuery Autocomplete Tokenizer Now after posting back the page, I want to re-load the values back into the textbox for whatever items had been entered.

Now the jQuery on the page is like below:

$(document).ready(function () {
        $("#<%=txtPeople.ClientID %>").tokenInput("Handler.ashx", {
            hintText: "Type in a name",
            noResultsText: "No results",
            searchingText: "Searching...",
            prePopulateFromInput: true  
            },
            prePopulate:  **Here is where I want to add JSON listing the items that should be populated**
        });
    });

If I add the JSON below within the prepopulate it loads the values the first time the form loads (And after any postbacks, so I need a way to make this a variable, that I can feed into the javascript on the page, and also have it updated by any client side changes)

[{"id":1,"name":"Ben"},{"id":2,"name":"Bernard"},{"id":3,"name":"Joe Bentley"}]

Can anyone point me in the right direction or give any references that may help? thanks

A: 

You should be able to assign the json to a variable as in..

string prepopulateValues="[{/"id/":1, /"name/":/"Ben/"}"; //etc.

then in your jquery function write out the value of the variable

prePopulate: <%= prepopulateValues%>
Tom B
Hi thanks for the reply, this appears to work after a postback, although I have the issue of having to set a value on the initial page load, otherwise it errors out and doesn't work. Any ideas?
BenW
Could you set the value for "prepopulateValues" in the Page_load event? If you put it in an If(!Postback)? Or am i misunderstanding what you mean?
Tom B
Yeah appears to work, seems very messy but im pretty new to javascript as it is
BenW