Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Products › Development › Forge › Component - WebControls Register  |  

 

dnn_ct_webcontrols_170x64.gif

 

  Quick Links  
 


  Team Leadership  

Jon Henning

jonhenning.jpg

 


  DotNetNuke Projects  
The DotNetNuke Projects are a special category of platform extensions which are developed by volunteers to conform to the high professional standards mandated by DotNetNuke Corporation. The DotNetNuke Projects are distributed as a standard part of the DotNetNuke core application release offerings.

 


The best choice for your web site host, email hosting, and domain registration.
  Ads  
Webhost4Life - $4.95 Windows Hosting
 


  Sponsors  

Meet Our Sponsors

Salaro -- Skins and more
OnyakTech
The best choice for your web site host, email hosting, and domain registration.
CrystalTech Web Hosting™
Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
 


DotNetNuke® Project :: WebControls

The primary purpose of the DotNetNuke WebControls project is to allow developers to utilize feature-rich controls in their applications without the associated cost or distribution restrictions associated with commercial controls. All controls utilize the ClientAPI, and therefore support a rich client side object model, work cross-browser, and utilize AJAX functionality.

The DotNetNuke TreeView control is an open-source ASP.NET WebControl that has a rich client-side object model and supports advanced featuresets like populate on demand and keyboard navigation.
The DotNetNuke Menu control is an open-source ASP.NET WebControl that has a rich client-side object model and supports advanced featuresets like populate on demand and keyboard navigation (soon).
The DotNetNuke Label Edit control is an open-source ASP.NET WebControl that allows any label to be editable on the client where it uses a client-callback to persist the changes. Simply specify a client-side event like onclick to allow the user to edit. It supports RichText and MultiLine editing.
The DotNetNuke Text Suggest control is an open-source ASP.NET WebControl that allows any textbox to suggest the results the user is looking for by dynamically populating a menu of matched items.
The DotNetNuke Tab Strip control is an open-source ASP.NET WebControl that allows a page to be displayed in a tabular manner. It supports 3 rendering modes, including AJAX on-demand loading to allow for optimal performance.
The DotNetNuke ToolBar control is an open-source ASP.NET WebControl that allows a toolbar to be attached to any control.
 


WebControls Project Blog
Feb 13

Posted by: Jon Henning
2/13/2007

Yesturday I blogged on the MS AJAX framework's PageMethod implementation falling short when it comes to control developers.  Before I completely gave up on this, I decided to investigate some of the toolkit's controls to see how they handle these callbacks.  Two controls came up in my search: Rating and ReorderList.  I spent some time investigating the Rating control, which seems to utilize the classic ASP.NET 2.0 callback mechanism.  The only issue I saw is that the control did not use the script returned to it by the GetCallbackEventReference method, rather it had hardcoded its call into its js file. While I don't anticipate that Microsoft will ever change this function declaration, I wouldn't want to bet on it.  The method I am referring to is WebForm_DoCallback.  I decided to search the entire toolkit for any other controls utilizing this approach.  I didn't find any other controls but I did find a script called BaseScripts which really peaked my interest.

_invoke : function(name, args, cb) {
    /// invokes a callback method on the server controlif (!this._callbackTarget) {

Seeing that this method is private, or at least meant to be since it is prefixed with an underscore, I tried to find where it is called from.  I had found nothing.  Perhaps it was only a partial implementation.  I decided not to give up, rather, I did another search to see how a control's _callbackTarget property could be set.  This search yielded this code in the ScriptObjectBuilder class

 

// determine if we should describe methods
foreach (MethodInfo method in instance.GetType().GetMethods(
  BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
{
    ExtenderControlMethodAttribute methAttr = 
      (ExtenderControlMethodAttribute)Attribute.GetCustomAttribute(
        method, typeof(ExtenderControlMethodAttribute));
    if (methAttr == null || !methAttr.IsScriptMethod)
    {
        continue;
    }

    // We only need to support emitting the callback target and registering  
    //the WebForms.js script if there is at least one valid method
    Control control = instance as Control;
    if (control != null)
    {
        // Force WebForms.js
        control.Page.ClientScript.GetCallbackEventReference(control, null, null, null);

        // Add the callback target
        descriptor.AddProperty("_callbackTarget", control.UniqueID);
    }
    break;
}

This was very interesting to me, for it seems that if we denote an internal method as being a ScriptMethod and as long as the method is public, static, or an instance method we are going to be "hooked up".
Note:  It seems odd that this is an or...  looks like a bug.  I would not assume you can have a private instance method and it still work. 

I decided to make a simple control to try out this seemingly undocumented functionality.

My control was very simple.  It inherits from the ScriptControlBase class, renders simple div tag with text, and has two methods marked as ExtenderControlMethod.

using System.Web.UI;
using System.ComponentModel;
using AjaxControlToolkit;

[assembly: WebResource("MyAjaxControls.SimpleCallback.SimpleCallback.js", 
    "application/x-javascript")]
namespace MyAjaxControls
{
    [ClientScriptResource("MyAjaxControls.SimpleCallback", 
      "MyAjaxControls.SimpleCallback.SimpleCallback.js")]
    public class SimpleCallback : ScriptControlBase
    {
        public SimpleCallback()
            : base(false) {}

        [DefaultValue("")]
        [Category("Appearance")]
        public string Text
        {
            get { return (string)(ViewState["Text"] ?? string.Empty); }
            set { ViewState["Text"] = value; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.Write(this.Text); 
            writer.RenderEndTag();
	//required to hook up element on client
            ScriptManager.RegisterScriptDescriptors(this); 
        }

        [ExtenderControlMethod]
        public string HelloWorld(string s)
        {
            return "hello: " + s;
        }

        [ExtenderControlMethod]
        public int Add(int x, int y)
        {
            return x + y;
        }
    }
}

The client side library was also simple.  It simply hooked up the click event of the element and invoked our callback

Type.registerNamespace("MyAjaxControls");

MyAjaxControls.SimpleCallback = function(element) {
    MyAjaxControls.SimpleCallback.initializeBase(this, [element]);    
    this._onclick$delegate = Function.createDelegate(this, this._onclick);
    this._cbcomplete$delegate = Function.createDelegate(this, this._cbcomplete);
}
MyAjaxControls.SimpleCallback.prototype = {
    
    initialize : function() {
        MyAjaxControls.SimpleCallback.callBaseMethod(this, "initialize");
        var element = this.get_element();
        $addHandler(element, "click", this._onclick$delegate);
    },

    dispose : function() {

        var element = this.get_element();
        if(element) {
            $removeHandler(element, 'click', this._onclick$delegate);
        }
        MyAjaxControls.SimpleCallback.callBaseMethod(this, "dispose");
        
    },
    
    _onclick : function(sender, e) {
        //this._invoke('HelloWorld', ['hi'], this._cbcomplete$delegate);
        this._invoke('Add', [20, 3], this._cbcomplete$delegate);
    },
    
    _cbcomplete: function(result, ctx)
    {
        alert(result);
    }
}

MyAjaxControls.SimpleCallback.registerClass("MyAjaxControls.SimpleCallback", AjaxControlToolkit.ControlBase);

I must say that I am really pleased to find this implementation.  Even though under the covers it is using a classic ASP.NET 2.0 callback, all the plumbing work to allow our multiple parameters along with any number of functions to be invoked is all handled for us.  I am not sure why the _invoke is private, or if this is even functionality that should be used by control developers.  Searching the internet was not helpful at all.  The only reference I found on the subject is this blog.

ScriptControlBase implements some great new features that hopefully soon will make their way into ExtenderControlBase before the next real release.  These include:

  • Load/Save ClientState methods similar to Load/Save ViewState on the server and client-side
  • ASP.NET 2.0 Callbacks
  • ScriptUserControl to create custom AJAX controls using .ascx files.  Facilitates creating reusable mashup controls when building web applications
  • ControlBase.prototype.findElement() client method to find child objects using .NET Naming Containers (ScriptControlBase is an INamingContainer)

If anyone out there can shed some light on this functionality I would really appreciate it.

Tags:

Re: Researching MS AJAX: ScriptControlBase and Callbacks

It's great that you are "taking it a part" :)

I've looked long and hard how to make full blown Ajax controls, and only recently found a reference in the same control toolkit to that Base class.

You can also take a look at the new Tab control in the toolkit as it implements the same base class and is a good example of such behavior.

One more thing... as you are now digging into MS Ajax, can you tell me what are the plans for inclusion in the core? At least of web.config / ScriptManager / binaries so that our modules can work without needing to modify the host before doing so?


regards,
Vladan Strigo

By vladan on   2/14/2007

Re: Researching MS AJAX: ScriptControlBase and Callbacks

Vladan,
Yeah, I have been looking at the Tab control as well. Regarding core integration, I have not done any more investigation on integration since my original proposal found in this blog http://www.dotnetnuke.com/Community/BlogsDotNetNuke/tabid/825/EntryID/407/Default.aspx.

Obviously there is much to consider. For the short term we will need to come up with a solution that does not require MS AJAX to be installed, whether in the GAC or in the bin folder with full trust. Failure to do so will alienate a portion of our users from being able to upgrade. I have only briefly read some of your postings in the forums. I admit I don't understand the need for some of your suggestions at the moment. If you wouldn't mind emailing me what steps are necessary and explaining why they are needed it would help jump start my understanding.

By jhenning@solpart.com on   2/14/2007

Re: Researching MS AJAX: ScriptControlBase and Callbacks

wesclyburn,
I do understand the need for having it integrated in the core. This was the main reason before Atlas ever existed to embark on the creation of the ClientAPI and DotNetNuke WebControls, for module developers need an easy, cheap, consistent and reliable way to provide rich client side experiences in their modules. With the latest release of the DNN WebControls out and MS AJAX actually in a released format, I finally can carve out some time to figure out how best to suggest integration in the core. This also includes integration of the ClientAPI and WebControls at some point as well.

By jhenning@solpart.com on   2/16/2007

Re: Researching MS AJAX: ScriptControlBase and Callbacks

Hi Jon,

I've sent you an email on the subject, feel free to contact me about anything, Ill try to help you as much as I can with my (limited) knowledge on the subject.


Vladan

By vladan on   2/15/2007

Re: Researching MS AJAX: ScriptControlBase and Callbacks

Inclusion in the core would be a worthwhile endeavor. Vladan uses a handler to ensure that-- assuming everyone uses it-- the scriptmanager is included only once per page, which allows him to not rely on changes to default.aspx or a particular skin. We used a skin object to accomplish the same thing. The reasons were that Ajax may be needed by multiple modules, and so packaging a handler with the module could be a problem later on. The Skin object is a separately installed entity, and in some cases allows the module controls to be written the same regardless of whether Ajax is installed-- they just handle postbacks like they always.

If anything, this points to the need to have a common pattern developers can use when developing for Ajax on DNN, preferably something that co-exists with overall ASP.NET development of which DNN is just a subset. Relying on homegrown solutions limits our integration options later on. New controls that save us time and moeny pop up all the time.

By on   2/16/2007

Re: Researching MS AJAX: ScriptControlBase and Callbacks

Jon,

Good job with the sample. We have not yet implemented callbacks within any of the controls yet although there are some places where it will be used in the near future. I have put together another blog post with more detail on how to use the callbacks and the risks involved. The post is here: http://community.bennettadelson.com/blogs/rbuckton/archive/2007/02/16/ASP.NET-AJAX-Control-Toolkit-_2B00_-ASP.NET-2.0-Callbacks_2100_.aspx

Feel free to drop a comment if there is anything you'd like more detail on. Once callbacks are supported in BehaviorBase and some controls and behaviors start using them we'll have more documentation in the toolkit itself.

By ronbuckton on   2/16/2007
 


AppTheory
Professional development for medium to large projects based on the DotNetNuke platform.
www.apptheory.com
OnyakTech
Modules for Help Desks, Live Chat, Project Management, CRM, Charting, Reporting, Scrolling Text/Images, Portal Community tools and much more.
www.OnyakTech.com
IHostASP.NET Provides the Ideal DNN Hosting
We will help you with the installation, configuration, and troubleshooting of your DNN portal, no task is too big or small for us. Unlike other companies we are not just providing a reliable hosting service, but we are also focused on providing the best DotNetNuke hosting service on the internet.
www.ihostasp.net

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP