Jaxcent for .NET

Getting Started with C#

In this section, an overview is provided by means of actual coding examples. The samples do include these as pre-built projects, but it is recommended that a few minutes be spent actually doing this.

Adding Jaxcent to a project

The installer adds a "Jaxcent" item into the standard Developer Studio "Add New Item" menu, in the "My Templates" section, as shown below.

This item can be used to insert the required Jaxcent files to a project. Adding a new Jaxcent item will

(Note that the name you specify to the "Add New Item" will be ignored.)

Getting stated with Jaxcent using a .aspx page

Create a C# ASP.NET Web Application project, and use the "Add New Item" menu to add Jaxcent to it. In the Default.aspx.cs code, add the following:

using Jaxcent.Web;
using Jaxcent.Web.Html;

and then in the class, declare

    public JaxcentPage jaxcentPage = new JaxcentPage();

In the .aspx HTML markup, add the following inside the <head> section

    <script type="text/javascript" src="JaxcentDotNet23.js?jaxcentid=<%= jaxcentPage.JaxcentConnectionID %>"></script>

This connects the HTML client page to this particular instance of the JaxcentPage object on the server. Note that jaxcentPage needs to be declared public so it can be accessed from the markup.

  Jaxcent coding for the .aspx file

Add the following to the Default.aspx markup

    <asp:Button ID="HelloButton" Text="Hello" runat="server"/>

inside the <form> created by Visual Studio. Also add

    <p id="MessageText"></p>

to the markup. This can be inside the form or outside.

In the code-behind Default.aspx.cs file, add declarations for a JaxcentInputButton and JaxcentPara objects in the class.


        JaxcentInputButton button;
        JaxcentPara message;

Then either add a constructor and in that constructor add the following code, or add this code in the existing Page_Load

            button = new JaxcentInputButton(jaxcentPage, "HelloButton");
            message = new JaxcentPara(jaxcentPage, "MessageText");

Here, we are telling Jaxcent that the object button is to be connected to the HTML INPUT button with ID "HelloButton" on the page, and that the message object is to be connected to the P with ID "MessageText".

Add an event handler to button's OnClick event as well, by entering button.OnClick, a space and += and then by pressing TAB twice to let Visual Studio generate the event framework.


            button.OnClick += new JaxcentEvent(button_OnClick);


and add some actions to the button_OnClick event handler

        void button_OnClick(JaxcentObject src)
        {
            // On button-click, update the message and show a message-dialog.

            message.InnerText = "You clicked hello at " + DateTime.Now;
            jaxcentPage.ShowMessageDialog("Hello, World!");
        }

You can now run the project, and click on the Hello button.

This shows some basic capabilities of Jaxcent - responding to events, changing HTML on the page, and showing a message-box to the user.

Getting stated with Jaxcent using a .html page

It is not necessary to use .aspx files, Jaxcent can also be used with .htm and .html files.

Create a C# Web Application project, and use the "Add New Item" menu to add Jaxcent to it. Then delete the Default.aspx from the project, and add an HTML page named Default.htm instead.

Add the following inside the <head> section in the Default.htm page


    <script type="text/javascript" src="JaxcentDotNet23.js"></script>

Since there is no existing code-behind for the page, we need to make a new class for it. Add a new class, let's say a class named HelloWorldPage. Add the Jaxcent "using" statements

using Jaxcent.Web;
using Jaxcent.Web.Html;

and make the class inherit from JaxcentPage

    public class HelloWorldPage : JaxcentPage

In the HTML markup, add a FORM with an input button with ID "HelloButton" in it, and a para (P) with ID "MessageText". In the code, add declarations for a JaxcentInputButton and JaxcentPara objects in the class.

        JaxcentInputButton button;
        JaxcentPara message;

Add a constructor and in that constructor add the following code:

            button = new JaxcentInputButton(this, "HelloButton");
            message = new JaxcentPara(this, "MessageText");

Just as with the .aspx page, also add the OnClick event handler for the button.

  Connecting HTML to the handler Class

We now have a class HelloWorldPage that's ready to handle the Default.htm page. But we need to tell Jaxcent that HelloWorldPage is connected to Default.htm.

This can be done via the "Global" class. Use "Add New Item" to add a "Global" class to the application. Then in the Global.asax.cs file, add


using Jaxcent.Framework;

and in the Application_Start method, add

            JaxcentFramework.GetInstance().AddURL("/default.htm", typeof(HelloWorldPage));
            JaxcentFramework.GetInstance().AddURL("/", typeof(HelloWorldPage));

This code is telling the Jaxcent framework that the URLs /default.htm and / (which loads default.htm) both should be handled by the HelloWorldPage class.

Now when the / or /default.html URLs are encountered, Jaxcent will instantiate a HelloWorldPage object, and connect that object to the browser page.


The above provides an introduction to the basics of Jaxcent.

Continue to C# Sample Projects