Setting WatermarkText in JavaScript

To set the Watermark Text of a TextBoxWatermarkExtender in the AJAX Control Toolkit, use the following code:

var behavior = $find('<%= TextBoxWatermarkExtender1.ClientID %>');
behavior.set_Text('Hello World!');

It took me a while to find that I needed to call the Initialize() function before the Watermark Text would get updated.

Update September 25, 2012

It appears that different versions of the AJAX Control Toolkit have different public methods.

var behavior = document.getElementById("<%= TextBox1.ClientID%>").AjaxControlToolkitTextBoxWrapper;

ASP.Net AJAX Animations

Some of the best resources for the animation framework that comes with the ASP.Net AJAX Control Toolkit can be found at the live toolkit site at this Sample Site. I often look at the Animation Reference section of this site.

While adding animations to ASP.Net pages, it is sometimes necessary to call animations directly from Javascript code. This can be achieved relatively easily using the great instructions at this MSDN blog.

Combined with the Animation Reference on website, any animation can be called directly from Javascript. If you can’t use the <OnLoad> animation event handler in the AnimationExtender control, one way to play animations on the page load is to use ClientScriptManager.RegisterStartupScript to create a function with the animation code, and call that function on the next line.

Page.ClientScript.RegisterStartupScript(Me.GetType, “PlayLoadAnimation”, “function playNotificationAnimation(){$get(“”divNotification””) , 1 , 30 , “”style”” , “”backgroundColor”” , “”#181840″” , “”#E9E8FF””); }”, True)

Page.ClientScript.RegisterStartupScript(Me.GetType, “LoadAnimationFunction”, “playNotificationAnimation();”, True)

Happy Animating!
Zachary Lyons