Embedding ASP.NET Server Variables into JavaScript

The ScriptVariables component allows you to easily embed server values into JavaScript by way of an object that is created based on key value pairs you define on the ScriptVariables component.

  • Allows embedding of values and objects from server code into JavaScript
  • Allows embedding of dynamic control/object values into JavaScript. Rendered at end of page request.
  • Optionally can persist changes back to the server
  • Provides a name/value collection to Client that can be retrieved on the server
  • Can create ClientID variables for servervariables in containers

Embedding of Server Variables

ScriptVariables scriptVars = new ScriptVariables(this,"serverVars");
scriptVars.Add("commentMaxLength", App.Configuration.CommentMaxLength);
scriptVars.Add("txtBodyId", txtBody.ClientID);
scriptVars.Add("txtAuthorId", txtAuthor.ClientID);


© West Wind Technologies, 1996-2016 • Updated: 12/19/15
Comment or report problem with topic