ASPSnippets

Alerts
Get notified when a new article is published.

Name
 
Email

Your email will always be private and will not be shared.

Follow us on twitter.
 
AJAX Control Toolkit Color Picker Control in ASP.Net
Author Name: Mudassar Khan Published Date: May 16, 2009
Filed Under :
AJAX
Views: 2761

Recently I got chance to explore the new Color Picker control in the ASP.Net AJAX Control Toolkit hence I decided to share my experience.

First you will have to download the latest binary of the AJAX Control Toolkit from CodePlex site. To download click here.

Once that is done you will need to Add Reference of the Ajax Control Toolkit DLL as shown in figure below



Adding reference of AJAX Control Toolkit



Once that is done build the website project and then add this tag to the aspx page.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

 

Then you will need a textbox which will hold the Hexadecimal value of the color, a Button that will trigger the color picker, a DIV in which we can view preview the colors and a script manager in order to run the ASP.Net AJAX Control Toolkit Controls.

 

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:textbox id="TextBox1" runat="server"  Width = "150px"/>

<br />

<div id="preview" style="width:70px;height:70px;border:1px solid #000;margin:0 3px;float:left">

</div>

<asp:Button ID="Button1" runat="server" Text="Choose Color" />

 

Finally we will add the AJAX Control Toolkit Color Picker Extendor Control

<cc1:colorpickerextender id="ColorPicker1" runat="server"

     targetcontrolid="TextBox1"

     samplecontrolid="preview"

     popupbuttonid="Button1"

     PopupPosition ="Right"

     OnClientColorSelectionChanged = "Color_Changed"

      />

   

   

As you will notice above the properties of the Color Picker

1.  targetcontrolid The Control which will display the hexadecimal color value.

2. samplecontrolid – The Control which will show the preview

3.  popupbuttonid – The Control which will trigger the color picker.

4. OnClientColorSelectionChanged – The JavaScript function to be called when the color is changed.

 

On the OnClientColorSelectionChanged event I am calling Color_Changed JavaScript function which is shown below

 

<script type = "text/javascript">

    function Color_Changed(sender)

    {

        sender.get_element().value = "#" + sender.get_selectedColor(); 

    }

</script>

 

The above function adds a Hash (#) as prefix to the color hexadecimal value in the textbox.

That’s all the ASP.Net AJAX Control Toolkit color picker is ready to use. The figure below displays its working



AJAX Control Toolkit Color Picker Example



This completes the article. You can download the sample code using the link below.

ColorPicker.zip (709.96 kb)


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share Page copy protected against web site content infringement by Copyscape

Related Articles

Comments

Add Comments

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment

Please note that all comments are moderated and will be deleted if they are
  • Not relavant to the article
  • Spam
  • Advertising campaigns or links to other sites
  • Abusive content.
There is no need to add BR tags. Simply press enter for new line

Name*  
Email*
Comment*  
Security code
Security code