AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1522&pId=-1
Working with TextBox Watermark Extender
page
by Nidal Arabi
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28334/ 39

Introduction

Sometimes when you deal with textboxes you may need to specify more information than the description. The TextBox Watermark extender is just the control you need.

This article will show an example of how I used the control to provide users with feedback about the extra preferences that a customer would need in order to enter information in the preferred way. Also, in this example we show how to emphasize the importance of some input elements by associating them with colors. The whole project is attached for your own review.

Requirements

In order to be able to work with ASP.NET AJAX Control Toolkit, the following should be available:

·         Microsoft Visual Studio 2005 (any version) or you can also use the free of cost Visual Web Developer Express 2005.

·         Download ASP.NET 2.0 AJAX Extensions and install them on your computer after installing Visual studio 2005.

·         Download ASP.NET AJAX Control Toolkit and install them on your computer after installing Visual Studio 2005 and AJAX Extensions. You can also download the Toolkit directly from CodePlex project site.

·         After the completion of installation, open Visual Studio 2005 or Visual Web Developer and add a tab in the Toolbox named AJAX Toolkit.

·         Right Click in this tab and choose add items. Browse to the sample directory of where you did extract the Toolkit, then to bin directory and choose the file named AjaxControlToolkit.dll.

This is all you need to do. You have installed AJAX Control Toolkit and you can start building your controls.

Well, you should be ready by now to begin AJAX Toolkit implementation.

Creating your Textbox watermark sample

Follow these easy steps to create your solution

1.      Start your Visual Studio 2005 IDE.

2.      Choose Create Web Site from the menu.

3.      In this sample application we will use the Visual Basic language for the sample application.

4.      Name the solution TextBoxWatermarkSample.

5.      Choose ASP.NET AJAX Control Toolkit Web Site.

6.      Choose File System in the location box.

7.      Click OK to create the project.

8.      Visual Studio 2005 will create your project with a Default.aspx page and likely a readme.txt. Go ahead and get rid of the latter file.

9.      Open Default.aspx page in design view.

10.  You'll notice that there is a control on the page already called script manager. (Well, AJAX is really a script based implementation of the language JavaScript.) In Short, Script Manager Control manages client script for Microsoft ASP.NET AJAX pages. By default, the Script Manager control registers the script for the Microsoft AJAX Library with the page. This enables client script to use the type system extensions and to support features such as partial-page rendering and Web-service calls.

11.  On the design surface, under the script manager control, write the word Name:  and drag a Textbox control.

12.  Below the first line, write the word Phone: and drag a Textbox near it.

13.  Create a new style sheet (name it stylesheet.css) and insert the following code.

.watermark 
{
 
      background: #FFAAFF;
}

14.  Open the default.aspx page in source mode and drag the style sheet below the title section to create a reference to it.

15.  Back into design mode, go to the Toolkit Toolbox and drag two Textbox watermarks extenders and drop them on the page.

16.  In the properties of the first extender choose targetcontrolid to be textbox1.

17.  In the properties of the second extender choose targetcontrolid to be textbox2.

18.  In the properties window, choose textbox1 and identifies the newly added options under the watermark title.

19. In the CSS style option type watermark and in the watermark text enter: First Name then Last Name.

20.  For the second textbox type watermark as CSS property and in the watermark text enter: (000) 00 0000000.

21.  Now your project is ready and you can test it. It is important to note that watermark is not a validation, it is only additional information provided.

Downloads
Conclusion

The Textbox watermark extender is simply an elegance feature that allows you to provide more interactive website. If you want your website to stand out from the rest, be sure to use these kind of extenders in a fair way.

Hope you enjoyed the article. Happy Ajaxfying and see you in the next article.



©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 10:44:35 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search