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.

 


  Ads  
r2i.ntegrated
 


  Sponsors  

Meet Our Sponsors

AspDotNetStoreFront - E-Commerce by Design - The Leading ASP.NET shopping cart platform for developers!
Click here to go to dev.live.com for Windows Live developer resources
SteadyRain
DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
Jango Studios - Skins, Modules and Hosting for DotNetNuke
 


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
Aug 20

Posted by: Jon Henning
8/20/2007

Sometimes I grow frustrated when trying to solve apparently simple things, that end up taking most of the day to come up with an answer.  And if the answer is one that is bordering on a hack, I am even more distraught. This happened to me again while trying to optimize the latest version of the webcontrols, that will now use the Microsoft AJAX extensions framework. The optimization deals with allowing the control to persist its current structure. For example, when you have a tree that supports populate on demand, and you expand a node, causing a callback to occur, the new structure should be persisted. When a postback occurs, the tree should remember its structure (including what nodes are expanded). The code for this was already done. It was being called with each node expand, and each node selection. A more optimal way to handle this would be to simply call this persistence logic just before submitting the page. Simple, right?

Uh, no actually. If you simply place an event handler on the form's onsubmit, you will only get notified when a submit button is pressed.  You will miss all other postbacks (like an autopostback from a dropdownlist). Knowing the MS AJAX framework has a nice object and event model I expected to find an event exposed. This search yielded no results, so I decided to have a look at what the Control Toolkit does.  There are two controls that need this same notification: TextBoxWatermark and ConfirmButton. The solution offered there was not as good as I'd hoped. The way these controls handle getting the event notification is as follows

1) Register the WebForm_OnSubmit event on the server with the following code

ScriptManager.RegisterOnSubmitStatement(this,typeof(ConfirmButtonExtender),"ConfirmButtonExtenderOnSubmit","null;");
ScriptManager.RegisterOnSubmitStatement(this,typeof(TextBoxWatermarkExtender),"TextBoxWatermarkExtenderOnSubmit","null;");

2a) When the control initializes on the client, the logic looks for the js function name that the ASP.NET runtime registers on the client. Note that neither registration method invokes a specific function (null as the last parameter)

function WebForm_OnSubmit() {
//Note:  other page logic may register additional functions here as well!
null;
return true;
}

2b) A check to verify that a previous onsubmit handler was not already registered. Note, this is done with a shared/static property (not on the instance).

if ((typeof(WebForm_OnSubmit) == 'function') && !AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit) {

3) Assign the previous onsubmit handler for the watermark shared/static property to the current onsubmit handler

AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit = WebForm_OnSubmit;


4) Assign a new function reference to the existing handler. 

WebForm_OnSubmit = AjaxControlToolkit.TextBoxWatermarkBehavior.WebForm_OnSubmit;

5) The shared/static method that was reassigned to WebForm_OnSubmit will first invoke the original onsubmit method, if it returns successfully it will then loop through all components/extenders currently registered, and if it is of the same type as the current one, invoke that instance's onsubmit handler

AjaxControlToolkit.TextBoxWatermarkBehavior.WebForm_OnSubmit = function() {
  var result = AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit();
  if (result) {
    var components = Sys.Application.getComponents();
    for(var i = 0 ; i < components.length ; i++) {
      var component = components[i];
      if (AjaxControlToolkit.TextBoxWatermarkBehavior.isInstanceOfType(component)) {
        component._onSubmit();
      }
    }
  }
  return result;
}

At first I did not think that this logic would work, as I felt that it would loose the onsubmit events of any other code that utilized the RegisterOnSubmitStatement. However, after further review, I now see that it should work fine, as it is kind of like a linked list approach.

Issues
The first of three issues I have with this is similar to my issue with how the toolkit makes assumptions about what ASP.NET generated javascript names will be, in the earlier case it was the assumption on the function named WebForm_DoCallback, in this case it is WebForm_OnSubmit. While I do not anticipate MS changing the names of these functions, it certainly is not a dependency I would willingly keep unless necessary, as it could break going forward.

The second issue is in how there is no global handler inside the toolkit for this logic. Rather it is up to each control to rewrite this somewhat clunky functionality.

The last issue lies in an additional dependency the ConfirmButton places on the TextBoxWatermark. Apparently, if a watermark and confirm button exist on the same page, the watermark's handler needs to execute first. Obviously, this has a major issue for anyone else wishing to implement similar logic, as the confirm button will need to be reworked for each of these controls.

Different Approach
Not willing to live with this set of shortcomings, I decided to look for other approaches. Unfortunately, I found none, so I decided to code my own. What I came up with is a new component called submitComponent, that lives in the dnn.controls client-side namespace. The following is how it works

1) The server-side logic needs to register the componentbr

RegisterSubmitComponent(Me.Page)

This in turn add the following to the WebForm_OnSubmit function generated to the client

 

function WebForm_OnSubmit() {
//Note:  other page logic may register additional functions here as well!
dnn.controls.submitComp.onsubmit();
return true;
}

2) The client-side dnn.controls script will instantiate the dnn.controls._submitComponent component, inheriting from Sys.Component.  Inheriting from Sys.Component gives our new class the event handler logic we are looking for (getHandler, addHandler, removeHandler). 

3) The control's script will add a handler for onsubmit, by calling the submitComponent's add_handler method

this._onsubmitDelegate = Function.createDelegate(this, this._onsubmit);
dnn.controls.submitComp.add_handler(this._onsubmitDelegate);

This approach does not have issue 1 listed above, as it does not hardcode the WebForm_OnSubmit method into the client-script, rather it uses the ASP.NET functionality as intended by registering the script to execute onsubmit.  The second issue is addressed as there is now a global component that can be used by each of my controls.  The last issue is not addressed by my component since I have no such requirements.  However, the component could easily add an additional parameter to the add_handler method to specify it must execute last.

I can't help but think that this logic is already implemented somewhere and I have missed it.  If anyone out there knows how to better handle this scenario please post a comment./p>

 

Tags:

Re: Capturing the OnSubmit Event

Jon, As always... reading your blog is very interesting

By locopon on   8/21/2007
 


Willhite & Sharron Realtors
Exemplary service for your Seattle Real Estate needs. It's what you deserve from your Realtor®!
www.alkihomes.com
PointClick DotNetNuke Solutions
PointClick Technologies provides high-end DNN Hosting for businesses.
PointClick.Net Hosted Solutions
Active Modules, Inc.
Creators of Active Forums, the best forum module for DotNetNuke
www.activemodules.com

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