[How Do I:] Create an ASP.NET AJAX Extender from Scratch?

Please install Silverlight or click download to watch video locally.

Learn how to create an ASP.NET AJAX extender for a standard ASP.NET server control. We are shown how to add server-side properties and client-side JavaScript to extend the behavior of the standard TextBox control, though the same approach can be applied to any other server control. For further help in creating an ASP.NET AJAX extender, please refer to the Creating a New Extender walkthrough.

Presented by Chris Pels

Duration: 15 minutes, 11 seconds

Date: 01 September 2007

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 10

Leave a Comment

jpeterson77 : On April 25, 2008 3:20 PM said:

Hi,

Great tutorial but I am getting an error on compilation.  In the bottom left corner of the browser it says "error on page" in the details section it says "DisabledButton is undefined at line 60".  This is in the $create command.  Any idea why this might be happening?  any help would be much appreciated.

cv_vikram : On August 07, 2008 3:58 PM said:

Very good tutorial..thanks

mosaguitar : On November 01, 2008 12:40 AM said:

HI,

it is realy helpful tutorial ,but i have problem the method return GetPropertyValue("TargetButtonID", "");

the errer messsage is

the name GetPropertyValue does not exist in the current context

can any body help in that .

mosaguitar : On November 01, 2008 12:40 AM said:

HI,

it is realy helpful tutorial ,but i have problem with the method return GetPropertyValue("TargetButtonID", "");

the errer messsage is

the name GetPropertyValue does not exist in the current context

can any body help in that .

hareshambaliya : On November 17, 2008 9:24 AM said:

Hi,

Great video, I am interested in more videos of extender. can you please send more detail on ajax extender.

sankarcganesh : On December 08, 2008 4:49 AM said:

any one can help me that i am a new to javascript .any body teach me

Danny117 : On December 16, 2008 11:42 AM said:

After watching this video everything just started to click.

Thanks

Dollarjunkie : On February 03, 2009 10:31 AM said:

Hi Chris,

I do hope I get answers to my Question here as I am cluesless as to what it is I have not been doing right here. I have watched this particular video at least 5 times and I still can not seem to get my own AJAX extender control to work as I expect it to. I have posted this same on the forum and still no responses so I figure, I might try to ask you directly.

I am a newbie to Javascript. I have an extender control that is supposed to work with a FileUpload and an Image control. What I want to happen is when a file is selected for upload, at the firing of the OnChange event, what my code is meant to do is show the image that is selected for upload. Problem is nothing seems to be happening. Below is the jScript I have, I followed your example above to create a server class for the wiring of behaviors. Problem is I do not know what else to tweak to get this working. Can you please help?

/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Ajax.UserControls");

Ajax.UserControls.ImagePreview = function(element) {

//initialize the base

Ajax.UserControls.ImagePreview.initializeBase(this, [element]);

// Initialize instance level fields

this._defaultimage = null;

this._previewimage = null;

this._targetimageid = null;

}

Ajax.UserControls.ImagePreview.prototype =

{

   //call initialize on this first

   initialize: function() {

       Ajax.UserControls.ImagePreview.callBaseMethod(this, 'initialize');

       // Get a reference to the associated element

       var fileuploadcontrol = this.get_element();

       // Wire up handler for onmouseover

       var delegate = Function.createDelegate(this, this._onChange);

       $addHandler(fileuploadcontrol, 'change', delegate);

       this._onChange();

   }, //end initialize

   dispose: function() {

       //Add custom dispose actions here

       Ajax.UserControls.ImagePreview.callBaseMethod(this, 'dispose');

   }, //end dispose

   //Properties

   get_DefaultImage: function() {

       return this._defaultimage;

   },

   set_DefaultImage: function(value) {

       this._defaultimage = value;

   },

   get_PreviewImage: function() {

       return this._previewimage();

   },

   set_PreviewImage: function(value) {

       this._previewimage = value;

   },

   get_TargetImageID: function() {

       return this._targetimageid;

   },

   set_TargetImageID: function(value) {

       this._targetimageid = value;

   },

   // Event Handlers

   _onChange: function() {

       // Get a ref to the image element

       var  img = $get(this._targetimageid);

       //be sure there is an imagecontrol to work with

       if (img && !img.disabled && img.src != this.get_PreviewImage()) {

           // Set the source to the preview image

           img.src = this.get_PreviewImage();

       }

       else {

           if (img.src != this.get_DefaultImage) {

               //set it to the disabled image immediately

               img.src = this.get_DefaultImage();

           }

       }

   }

}

Ajax.UserControls.ImagePreview.registerClass('Ajax.UserCont rols.ImagePreview', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

ex glider pilot : On June 12, 2009 12:43 PM said:

Hi I have a web project (type file) and I have added the sample files, checked my references are there, complied the project and i can see the dll in the customextenders folder - but i do not get the control added to the tool box.. any suggestions what might be wrong? I tried manually adding a refernce to the customcontrol.dll still no sign of the controls in the toolbox

panand : On August 09, 2009 10:09 PM said:

The $create error is an unpredicatable error caused by 2 issues:

1. The curly braces are missing after the function keyword

AND/OR

2. The comma that separates the property accessors and the function proto-types is missing (Chris makes a mention of this explicity in the tutorial that the commas are not to be forgotten)

3. Also, test your app in FireFox. The Error Console will produce a URL to the .axd javascript source. If you click on the URL, the javascript is rendered in a Firefox window with the location of the error highlighted.

Putting the 2 together, here's what the code must look like:

set_DisabledText : function(value) {

this._disabledTextValue = value;

}, //**DO NOT FORGET THIS SEPERATOR- COMMA **

_onkeyup: function() //**DO NOT FORGET THESE BRACES **

{... rest of the code ..} //** NO COMMA IF THIS IS THE LAST PROTOTYPE OR ACCESSOR

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities