This component supports:
You create a script variables instance and add new keys to it:
ScriptVariables scriptVars = new ScriptVariables(this,"scriptVars"); // Simple value scriptVars.Add("userToken", this.UserToken); AmazonBook tbook = new AmazonBook(); tbook.Entered = DateTime.Now; // Complex value marshalled scriptVars.Add("emptyBook", tbook); scriptVars.AddDynamic("author", this.txtAuthor,"Text"); // Cause all client ids to be rendered as scriptVars.formFieldId vars (Id postfix) scriptVars.AddClientIds(this.Form,true);
In client code you can then access these variables:
$(document).ready( function() {
alert(scriptVars.book.Author);
alert(scriptVars.book.Author);
});
System.Object
Westwind.Web.Controls.ScriptVariables
public class ScriptVariables : object
Member | Description | |
---|---|---|
Constructor | Full constructor that receives an instance of any control object and the client name of the generated script object that contains the specified properties. | |
Add | Adds a property and value to the client side object to be rendered into JavaScript code. VariableName becomes a property on the object and the value will be properly converted into JavaScript Compatible text. public void Add( string variableName, object value ); | |
AddClientIds | Adds all the client ids for a container as properties of the client object. The name of the property is the ID + "Id" Example: txtNameId public void AddClientIds( Control container, bool recursive ); public void AddClientIds( Control container ); | |
AddDynamicValue | Adds the dynamic value of a control or any object's property that is picked up just before rendering. public void AddDynamicValue( string variableName, object control, string property ); | |
AddScriptAfter | Any custom JavaScript code that is to immediately follow the client object declaration. This allows setting up of namespaces if necesary for scoping. public void AddScriptAfter( string scriptCode ); | |
AddScriptBefore | Any custom JavaScript code that is to immediately preceed the client object declaration. This allows setting up of namespaces if necesary for scoping. public void AddScriptBefore( string scriptCode ); | |
GetItemValue | public TType GetItemValue( string key ); | |
GetValue | public TType GetValue( string key ); | |
AutoRenderClientScript | Determines whether the output object script is rendered automatically as part of Page PreRenderComplete. If false you can manually call the RenderClientScript() method to retrieve the script and embed it yourself. | |
ClientObjectName | The name of the object generated in client script code | |
UpdateMode | Determines how updates to the server from the client are performed. If enabled changes to the client side properties post back to the server on a full Postback. |