Creating a Custom Tooltip Ajax Extender Control
page 2 of 7
by Abdulla Hussein AbdelHaq
Feedback
Average Rating: 
Views (Total / Last 10 Days): 34374/ 48

Brief explanation about creating a new Ajax extender

What is Ajax extender control?

Ajax extender control is a control whose purpose is to add a behavior to the existing ASP.NET controls. These behaviors usually are client side behaviors that will extend the functionality of an existing ASP.NET control. I mention the sentence "an existing ASP.NET control" twice, to ensure the concept of Ajax Extender controls. The difference between Ajax extender control and custom server controls is that the custom server controls allow you to create a new server control that will work separately without extending any other controls. 

One of the interesting features that Ajax extenders offer is calling web services; we can hit the server and get some data from it without making the end-user notice. For example, the AutoComplete Extender Control uses the web service for filtering the typed text from Database without any flickers.

You can find a lot of resources and articles that talk about Ajax extenders, especially here in aspalliance.com.

ASP.NET Ajax controls project

To create a new Ajax extender, open your Visual Studio, and then create a new ASP.NET AJAX Control Project, as illustrated in Figure1.

Figure1

projecttypePic2

By default, this will create three files:

·         <your extender name>Behavior.js file: an embedded JavaScript file, where we will locate our client-side logic.

·         <your extender name>Designer.vb file: a class that enables design-time functionality. You should not need to modify it.

·         <your extender name>Extender.vb file: a server-side control class that will manage the creation of your extender, and allow you to set the properties at design-time. It also defines the properties that can be set on your extender. These properties are accessible via code and at design time and match properties defined in the Behavior.js file.

Ajax Library Shortcuts

There are several shortcuts methods for writing client-side functionality, such as:

·         $addhandler: enables you to assign a handler function to an event

·         $clearhandlers: clears all the handlers that you have created

·         $removehandler: removes a specific event handler

·         $get: a shortcut for document.getElementById

·         $find: allows you to access the class object, and use the methods and properties

Ajax Extender Logic

Ajax extender logic is quite simple; the following steps explain this process with code samples.

Create a property in the Extender.vb class, similar to what I did in Listing 1.

Listing 1

<ExtenderControlProperty()> _
<DefaultValue("")> _
Public Property MyProperty() As String
Get
Return GetPropertyValue("MyProperty", "")
End Get
Set(ByVal value As String)
SetPropertyValue("MyProperty", value)
End Set
End Property

Declare a property variable at initializeBase function in the Behavior JavaScript file, as illustrated in Listing 2.

Listing 2

this._myProperty = null; //Property Variable

Write get/set property for the above variable, as in Listing 3, and remember it is case sensitive.

Listing 3

get_MyProperty: function()
{
  return this._myProperty;
}
,
set_MyProperty: function(value)
{
  this._myProperty = value;
}
,

Create a JavaScript function, which will be the container of your client-side logic.

Listing 4

_myFunction : function(e)
{
  alert(this._myProperty);
}

Finally, add an event handler using the Ajax Library Shortcut $addhandler inside the initialize function, as you can see in Listing 5. We added an event handler for the mouse over event, but note that we have removed the "on" prefix word and that is the role.

We have created a delegate function that will be mapped to the _myFunction function, which will be fired when the mouse is going to be over the extended control.

Listing 5

$addHandler(this.get_element(), 'mouseover', 
Function.createDelegate(this,this._myFunction));

Build the project, and that is it; you have created a simple Ajax Extender control.


View Entire Article

User Comments

Title: ytu   
Name: tyu
Date: 2012-10-11 1:17:44 AM
Comment:
rtyu
Title: Mr   
Name: Mohar
Date: 2010-07-26 2:29:36 PM
Comment:
Not working for me it's giving following error:
System.InvalidOperationException: The TargetControlID of '' is not valid. The value cannot be null or empty.
Title: Mr.   
Name: Raju Balagam
Date: 2010-04-15 5:41:39 AM
Comment:
This artical helps to understand the cutom tooltip using ajax.....
Title: Good article   
Name: shailesh arban
Date: 2009-06-17 5:26:37 AM
Comment:
I gone through this article,It's very good article for those who wants to create own ajax extender.
Title: Re: 1 help ..   
Name: Abdulla [The Author]
Date: 2008-11-14 12:27:40 PM
Comment:
if you download the source code, you will find a javascript file which is the responsible for creating the tooltip, you need to change the horizontal/vertical offset in the initializeBase method into :
this.vertical_offset="-30px"
this.horizontal_offset="150px"

and if you want your code to be your more professional, you need to pass the offset of the webcontrol and calculate it with the div offset and here you will got the proper position.
Title: 1 help ..   
Name: sandeep ramani
Date: 2008-11-14 10:39:57 AM
Comment:
In above article...how i can change the position where tooltip is apearing..
i want to display tooltip not below the textbox ..but parallel to it,, so how to set that.. please tell me abt it..
Title: great article..   
Name: sandeep ramani
Date: 2008-11-14 10:20:12 AM
Comment:
this is very useful article..

it helped me a lot..

thank u very much..
Title: Good Article   
Name: Pavan
Date: 2008-10-08 2:07:31 AM
Comment:
It is a very good articles. I prefer the people to check this article before creating any ajax extenders. Thanks for the authors and contributers
Title: ms   
Name: VS2005
Date: 2008-08-08 10:13:10 AM
Comment:
Great job!!! Thank you!
Title: Re: uh. . VB/VWDEE 2008   
Name: Abdulla AbdelHaq
Date: 2008-08-06 9:01:46 AM
Comment:
Yes .. It is the same thing.
Actually, developing new Ajax Extender using VS 2008 is much easier than using VS 2005.
Title: uh. . VB/VWDEE 2008   
Name: Kevin Tweedy (KevInKauai)
Date: 2008-08-05 4:57:42 PM
Comment:
Interesting extension, but for those of us who only use VWD EE 2008 is it possible to have the implementation of this as a "done" package?

tia ... alohas ... KevInKauai
Title: Very Good   
Name: Vagueraz
Date: 2008-08-01 3:11:23 AM
Comment:
It's agreat article indeed ...
Go on Abdulla :)






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 9:51:58 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search