Search code examples
jsond3.jsvisual-web-gui

Passing a JSON object from visualwebgui to a htmlbox html page?


I have a situation where I am using Gizmox VWG 6.4 and a HTML page to surface some D3js visualisations.

Currently I am generating the data with no problems. The end result is that I have a JSON object in the correct format for my D3js app. What I need to do is somehow host the HTML within Gizmox VWG (presumably via HtmlBox??), and then somehow make the JSON object available to the HtmlBox so the HTML/JS app can read that? Ideally without having to store the JSON on disk?

Any ideas if this is even possible??

Thanks.


Solution

  • Sure this is possible using Visual WebGUi gateway to feed the HtmlBox. Say you have a Form with an HtmlBox, you can do the following:

    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Web;
    
    using Gizmox.WebGUI.Common;
    using Gizmox.WebGUI.Common.Gateways;
    using Gizmox.WebGUI.Forms;
    
    namespace VisualWebGuiApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                NameValueCollection NVC = new NameValueCollection();
                NVC.Add("JsonParm1", "value1");
                NVC.Add("JsonParm2", "value2");
                this.htmlBox1.Url = (new GatewayReference(this, "generateJSON", NVC)).ToString();
            }
    
            protected override Gizmox.WebGUI.Common.Interfaces.IGatewayHandler ProcessGatewayRequest(Gizmox.WebGUI.Hosting.HostContext objHostContext, string strAction)
            {
                if (strAction == "generateJSON")
                {
                    // make sure no caching takes place.
                    objHostContext.Response.Expires = -1;
                    objHostContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    objHostContext.Response.CacheControl = "no-cache";
                    objHostContext.Response.AddHeader("Pragma", "no-cache");
    
                    // Get the parameters from the gateway reference
                    string strParm1 = objHostContext.Request["JsonParm1"].ToString();
                    string strParm2 = objHostContext.Request["JsonParm2"].ToString();
    
                    // build your output and set content type
                    objHostContext.Response.ContentType = "text/html";
                    objHostContext.Response.Write("the data you want to write");
    
                    objHostContext.Response.Flush();
                    return null;
                }
                else 
                    return base.ProcessGatewayRequest(objHostContext, strAction);
            }
        }
    
    }
    

    Gateways are in fact a really powerful feature of VWG. See Here

    Hope this helps, Palli