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", UserToken); AmazonBook tbook = new AmazonBook(); tbook.Entered = DateTime.Now; // Complex value marshalled scriptVars.Add("emptyBook", tbook); scriptVars.AddDynamic("author", txtAuthor,"Text"); // Cause all client ids to be rendered as scriptVars.formFieldId vars (Id postfix) scriptVars.AddClientIds(Form,true);
In client code you can then access these variables:
$( function() { alert(scriptVars.book.Author); alert(scriptVars.author); alert( $("#" + scriptVars.txtAmazonUrlId).val() ); });
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 JSON 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 | 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);
|
|
GetClientScript | Returns the rendered JavaScript for the generated object and name. Note this method returns only the generated object, not the related code to save updates. public string GetClientScript(bool addScriptTags);
|
|
GetItemValue<TType> | Returns a value from the client Items collection public TType GetItemValue<TType>(string key);
|
|
GetValue<TType> | Returns a value that has been updated on the client public TType GetValue<TType>(string key);
|
|
AutoRenderClientScript | Determines whether the output object script is rendered automatically as part of Page PreRenderComplete. If false you can manually call the GetClientScript() method to retrieve the script as a string 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. |