ASP.NET Custom Server Controls: Cute ToolTip Control - What are the properties declared and how do we work with the control?
(Page 2 of 5 )
As I wanted the tooltip control to be as simple as possible, I declared only one property i.e., “IsDesignTime”. It is declared as “private” within the control class. It is created with the following code:
Private ReadOnly Property IsDesignTime()
Get
Return (Not Me.Site Is Nothing) AndAlso
(Me.Site.DesignMode)
End Get
End Property
It checks whether the control is at the stage of design-time or run-time. This is essential for me to determine whether the control needs to emit required JavaScript or not. During design-time, no JavaScript emission is necessary! It needs to be emitted only at run-time. You also need to observe that the property is “readonly” (no changes) and it is private (can be used only within the class and not outside the class). I used it only within the “Render” method.
To work with this control, we need to drag it from the toolbox (after adding it to the toolbox) onto the design surface. We can drag it to any location, as it is by default invisible at run-time. After placing it on the surface, we need to bind the tooltip to all of our respective controls during the “page load” event. The following is the code-fragment I used as part of the demonstration.
Me.TextBox1.Attributes.Add("onMouseOver", "showToolTip
(event,'<font face=\'verdana\' size=2>this is some
info</font>');")
Me.TextBox1.Attributes.Add("onMouseOut", "hideToolTip();")
The first statement adds the “OnMouseOver” event attribute to “TextBox1” by calling the JavaScript function “showToolTip”. This is similar to the second statement with “onMouseOut” event and “hideToolTip” JavaScript function.
In that way, the same control can be used by any number of controls which exist on the same web page.
Next: How is it rendered? >>
More ASP.NET Articles
More By Jagadish Chaterjee