Ajax Control Extensions for ASP.NET with Gaia Ajax 3.5

by Jan Blomquist 21. February 2009 20:05
Retro Tv

To lessen the learning curve of creating custom control extensions for Gaia Ajax, we've added some ItemTemplates to Visual Studio both for VB.NET and C#.

Some people have commented that Gaia Ajax doesn't offer a good client side story; This is simply not true. Gaia Ajax offers a plethora of ways for you to write both the client and server layer. Connecting the parts together through our Ajax machinery is an option, not a core requrement. 

Instead of writing a long blog about this, we've published a video tutorial instead (approx. 28 minutes) that you can find in our Gaiaware TV center. The video is available for download or online viewing (Flash)

In this video we're covering how to create a simple control extension with a thin javascript file available. It's the purpose of this tutorial to mostly be concerned about connecting the client and server parts together with the Gaia Ajax machinery.

Quick Agenda overview

  1. Creating the Project and adding the control
  2. Discussing the anatomy of a Gaia Control
  3. Serializing Property changes to the client
  4. Sending method calls to the client
  5. Calling the server from the client and dispatching an event

Overview of the code written in this video

C# Code

   1:  /* Gaia Ajax HelloGaia Template for Simple Extensions */
   2:   
   3:  using System.Web.UI;
   4:  using Gaia.WebWidgets;
   5:   
   6:  [assembly: WebResource("Gaiaware.CustomExtensionControls.HelloGaia.js", "text/javascript")]
   7:   
   8:  namespace Gaiaware.CustomExtensionControls
   9:  {
  10:      using System;
  11:      using Gaia.WebWidgets.HtmlFormatting;
  12:   
  13:      /// <summary>
  14:      /// Gaia Ajax HelloGaia 
  15:      /// </summary>
  16:      public class HelloGaia : GaiaControl, IAjaxControl
  17:      {
  18:          public event EventHandler Clicked;
  19:   
  20:          [Method]
  21:          internal string ClickedMethod()
  22:          {
  23:              if (Clicked != null)
  24:                  Clicked(this, new EventArgs());
  25:   
  26:              return string.Empty;
  27:          }
  28:   
  29:          protected override void IncludeScriptFiles()
  30:          {
  31:              base.IncludeScriptFiles();
  32:   
  33:              // Include Attached Javascript file
  34:              Manager.Instance.AddInclusionOfFileFromResource("Gaiaware.CustomExtensionControls.HelloGaia.js", 
  35:                  typeof(HelloGaia), "Gaiaware.HelloGaia.browserFinishedLoading", false);
  36:   
  37:          }
  38:   
  39:          public void SayHello()
  40:          {
  41:              _sayHello = true;
  42:          }
  43:   
  44:          private bool _sayHello;
  45:   
  46:          [AjaxSerializable("sayHello")]
  47:          private bool SayHelloMethod
  48:          {
  49:              get { return _sayHello; }
  50:          }
  51:   
  52:   
  53:          [AjaxSerializable("setCssClass")]
  54:          public string CssClass
  55:          {
  56:              get { return ViewState["CssClass"] == null ? "" : ViewState["CssClass"] + ""; }
  57:              set { ViewState["CssClass"] = value; }
  58:          }
  59:   
  60:          protected override void RenderControlHtml(XhtmlTagFactory create)
  61:          {
  62:              using (Tag root = create.Div(ClientID))
  63:              {
  64:                  root.WriteContent("Hello Gaia");
  65:              }
  66:          }
  67:   
  68:          #region IAjaxControl Members
  69:   
  70:          string IAjaxControl.GetScript()
  71:          {
  72:              // Register the Control ClientSide
  73:              return new RegisterControl("Gaiaware.HelloGaia", ClientID).ToString();
  74:          }
  75:   
  76:          #endregion
  77:      }
  78:  }

JavaScript

   1:  /* Gaia Ajax Extension */
   2:   
   3:  // Create root namespace
   4:  if( !window.Gaiaware )
   5:    Gaiaware = Class.create();
   6:   
   7:  // Create the Extension Control
   8:  Gaiaware.HelloGaia = Class.create(Gaia.Control, {
   9:   
  10:      // Constructor
  11:      initialize: function(element, options) {
  12:          this.initializeHelloGaia(element, options);
  13:      },
  14:   
  15:      initializeHelloGaia: function(element, options) {
  16:          // Calling base class constructor
  17:          this.initializeControl(element, options);
  18:   
  19:          Element.observe($(element), 'click', this._onClick.bind(this));
  20:      },
  21:   
  22:      _onClick: function(evt) {
  23:          Gaia.Control.callControlMethod.bind(this)('ClickedMethod', null, null, this.element.id);
  24:      },
  25:   
  26:      setCssClass: function(value) {
  27:          $(this.element).className = value;
  28:          return this;
  29:      },
  30:   
  31:      sayHello: function(value) {
  32:          alert('Hello');
  33:          return this;
  34:      },
  35:   
  36:      // Destructor
  37:      destroy: function() {
  38:          // TODO: Put destruction code here
  39:      }
  40:   
  41:  });
  42:   
  43:  Gaiaware.HelloGaia.browserFinishedLoading = true;

If you like the video tutorials we're creating and find them useful, please give us some feedback on it. Are we touching base?

Until next time Smile 

Tags:

Tutorials

Comments

3/7/2009 4:25:07 AM #

Great article.. thanks for sharing,, that's useful...

Kampanye Damai Pemilu Indonesia 2009

3/22/2009 1:19:20 PM #

Thanks for sharing your thought. Wish you good luck for your future endeavors.

Kampanye Damai Pemilu Indonesia 2009

3/25/2009 2:34:32 AM #

Thanks for sharing your knowledge...

Hangga Nuarta

3/25/2009 2:35:41 AM #

Thank you for sharing... nice article....

Tukang Nggame

3/25/2009 7:31:35 PM #

great discussion, i like it.

phreakaholic

4/1/2009 2:52:04 PM #

I like Ajax Very much.... Thanks for sharing Ajax info

devix

4/4/2009 11:15:30 AM #

it's very interesting discussion, i like it.

blogging tips

4/6/2009 2:30:52 PM #

First of all, thanks for the info.

Now, what's the deal with AJAX?

Why is it so famous?

Because google is using it?

Or is it really good??

Cheers.

mago fiestas

4/11/2009 2:10:55 PM #

thanks you for this usefull informations..
now i find what i want to know.. thanks..

Kampanye Damai Pemilu Indonesia 2009

4/16/2009 2:31:04 AM #

Thank you, this script is very useful for me!

md5 hash

4/16/2009 2:32:41 AM #

Thanks for informing..

computer zone

4/16/2009 2:33:55 AM #

usefull script, thank you!

free download software

4/16/2009 2:35:22 AM #

thanks for sharing, very usefull for me

article computer

4/16/2009 2:37:27 AM #

I like ajax, keep this!

nangka

4/19/2009 7:11:24 PM #

hi, this is the first time i visit here, your blog is so interesting. i love your theme.

free insurance quotes

4/22/2009 12:49:02 AM #

Amazing blog, thank you.




<a href="http://parafarmaciamasbarata.es> Farmacia</a>
<a href="http://123farmaciaonline.es> Farmacia</a>
<a href="tiendainformaticagalaica.es>Informatica</a>
<a href="http://expressmining.com.au>ROPS</a>

Informatica

4/22/2009 12:50:38 AM #

Thank you

Farmacia

4/22/2009 12:50:59 AM #

Thank you

ROPS

4/22/2009 12:51:15 AM #

Thank you

Farmacia

4/22/2009 9:23:25 AM #

what a great info, thanks.

Carissa Putri

4/28/2009 7:26:31 AM #

thanks you for this usefull informasion..
i get something what i want to now.. thanks..

Kampanye Damai Pemilu Indonesia 2009

4/30/2009 8:36:32 AM #

Nice Blog, wait for next post..

Street to Smart

4/30/2009 2:54:28 PM #

Nice Posting here, anyway thanks for Posting

Love Tips for Teens

5/1/2009 2:01:23 AM #

what a great blog, i really like it.

Tukang Nggame

5/1/2009 10:52:13 AM #

thanks for sharing...

Hoodia Gordonii Plus Reviews

5/4/2009 9:18:02 AM #

It is really nice post.

hdmi cable

5/8/2009 7:52:23 AM #

very nice info, thanks.

sulumits retsambew

5/9/2009 1:14:00 AM #

great blog, i really like it.

tukang nggame

5/9/2009 2:36:51 PM #

thanks for sharing

le vin

5/13/2009 7:21:07 AM #

Thanks for sharing your knowledge...

Bisnis Online

5/13/2009 7:24:27 AM #

just wanna say thanks

tukang nggame

5/13/2009 7:24:58 AM #

thanks to..

tukang nggame

5/13/2009 7:31:45 AM #

btw is blogengine.net free..?

blogger tips

5/16/2009 7:18:31 PM #

great blog, i like it.

beware

5/17/2009 7:17:21 AM #

@bloggertips yes it is free.
Great post
Thanks

cigarest

5/17/2009 7:17:49 AM #

Great Knowledge indeed

ciggarest

5/17/2009 7:18:10 AM #

how can you post code like that?

ciggarrest

5/17/2009 11:47:01 AM #

thanx a lot... this was really useful

melissa

5/17/2009 1:49:16 PM #

Great tutorial admin!!! Smile

health tips and medicine

Comments are closed