As Joe Enos pointed out, ViewState
is part of the page instance, but you can use Session
cache, like this:
[WebMethod(EnableSession = true)]
[ScriptMethod]
public static string populateModels(string[] makeIds)
{
// Check if value is in Session
if(HttpContext.Current.Session["SuperSecret"] != null)
{
// Getting the value out of Session
var superSecretValue = HttpContext.Current.Session["SuperSecret"].ToString();
}
// Storing the value in Session
HttpContext.Current.Session["SuperSecret"] = mySuperSecretValue;
}
Note: This will also allow you to use part of your page with ASP.NET AJAX Page Methods to just get or store some values to the server, while also allow your page postbacks to have access to the data via Session
as well.