using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Westwind.Web.Controls;
using System.Collections.Generic;
using ScriptCallbacks.BusinessObjects;

public partial class ScriptVariablesPage : System.Web.UI.Page
{
    ScriptVariables scriptVars = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        // *** pass page reference and name of the client side objects (both optional)
        ScriptVariables scriptVars = new ScriptVariables(this,"serverVars");
        scriptVars.UpdateMode =  AllowUpdateTypes.All;

        // *** Create a 'namespace'
        //scriptVars.AddScriptBefore("var MyNameSpace = {};\r\nMyNameSpace.Custom = {};");

        // *** Add any values static or dynamic
        scriptVars.Add("name", "Rick Strahl");
        scriptVars.Add("company", "Rick's \"East\\West\" Trading");
        scriptVars.Add("entered", DateTime.Now.AddYears(-10));
        scriptVars.Add("counter",12.22M);

        // *** Add a control's value
        scriptVars.AddDynamicValue("txtNameValue", this.txtName, "Text");
        
        // *** A cleaner way to get ClientIDs into client code
        //scriptVars.Add("txtNameId", txtName.ClientID);
        //scriptVars.Add("btnSubmitId", btnSubmit.ClientID);

        // *** Add all Client Ids - note this may cause naming conflicts on duplicate names
        // *** in separate naming containers. First one wins!
        scriptVars.AddClientIds(this,true);

        // *** Read back values assigned to the client script object
        if (this.IsPostBack)
        {
            Response.Write(scriptVars.GetValue<string>("name"));
            Response.Write(scriptVars.GetItemValue<string>("Custom"));
            Response.Write(scriptVars.GetItemValue<string>("CustomValue"));
            Response.Write(scriptVars.GetItemValue<DateTime>("curDate"));
            Response.Write(scriptVars.GetValue<DateTime>("entered"));
            int x = 0;
        }

        //scriptVars.AddScriptAfter("var serverVars = MyNameSpace.Custom.serverVars;");

        // *** Done
    }
}
