Click here to Skip to main content
Click here to Skip to main content

ASP.NET Color Picker Web Server Control

By , 6 Apr 2010
 
ColorPickerDemo.png

Introduction

It is difficult to find a decent color picker control for ASP.NET. However, there are plenty of pure JavaScript color picker controls. I decided to take one of them and convert it into an ASP.NET web server control. As a base, I took the dhtmlgoodies advanced color picker.

Project Setup

First, let's do New Project ->ASP.NET Server Control. By default, the name of the project would be the same as the name of the default namespace. I called my project WebControls, and renamed ServerControl1.cs to ColorPicker.cs. I changed default namespace to Karpach.WebControls, as well as assembly name. Then, I added to the project the images, JavaScript, and styles supplied by dhtmlgoodies.

CustomControlSolutionFiles.gif

Then, I clicked on each file's properties and changed the Build Action from Content to Embedded Resource. I also renamed some of the files.

AssemblyInfo.cs

I registered all the resources like this:

[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.SliderHandle.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.TabCenterActive.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.TabLeftActive.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.TabLeftInactive.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.TabRightActive.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.TabRightInactive.gif",
    "img/gif")]
[assembly: System.Web.UI.WebResource("Karpach.WebControls.Images.ColorPickerIcon.jpg",
    "img/jpeg")]


[assembly: System.Web.UI.WebResource("Karpach.WebControls.Styles.ColorPicker.css",
    "text/css")]

[assembly: System.Web.UI.WebResource("Karpach.WebControls.Javascript.ColorPicker.js",
    "text/js")]

As you might have noticed, System.Web.UI.WebResource, the first parameter has the following signature:

[Assembly Name].[Folder].[File Name]

This is very important, since it is not documented even in MSDN.

ColorPicker.cs

In order to enable Validators for your control, you need to specify ValidationProperty attribute of your server control class.

[DefaultProperty("Color"),ValidationProperty("Color")]

I modified ToolboxData to look like this:

[ToolboxData("<{0}:ColorPicker runat="server">")]

Next, I wanted a custom icon in the Visual Studio Toolbox. After ToolboxData, I added the following line:

[System.Drawing.ToolboxBitmap(typeof(ColorPicker),"Images.color_picker_icon.jpg")]

where the first parameter is the type of the control and the second parameter is the icon file name used in AssemblyInfo.cs.

Originally color picker had two JavaScript files: color_functions.js and js_color_picker_v2.js. I combined them in one file, ColorPicker.js. Those files had a bunch of functions. I combined everything in one JavaScript class, exposed some public properties and one public function ShowColorPicker.

function ColorPicker(options)
{
    // Public properties
    this.FormWidgetAmountSliderHandleImage = options.FormWidgetAmountSliderHandleImage;
    this.TabRightActiveImage = options.TabRightActiveImage;
    this.TabRightInactiveImage = options.TabRightInactiveImage;
    this.TabLeftActiveImage = options.TabLeftActiveImage;
    this.TabLeftInactiveImage = options.TabLeftInactiveImage;
    this.AutoPostBack = options.AutoPostBack;
    this.AutoPostBackReference = options.AutoPostBackReference;
    this.PopupPosition = options.PopupPosition;

    // Public methods

    this.ShowColorPicker = function(inputObj, formField)
    {
	  //.....
	}
	// Private variables
	// ....
	
	// Private functions
    // ....
}

After some feedback, I had to fix JavaScript in order to support ASP.NET AJAX UpdatePanel and ModalPopup extender.

Then, I needed to load the stored resources from the DLL into JavaScript class. The best event for this is OnPreRender:

// Javascript
string colorFunctions = Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker),
			"Karpach.WebControls.Javascript.ColorPicker.js");
Page.ClientScript.RegisterClientScriptInclude("ColorPicker.js", colorFunctions);

// Create ColorPicker object
string script = string.Format(@"
var colorPicker_{0} = new ColorPicker({{
FormWidgetAmountSliderHandleImage : '{1}',
TabRightActiveImage : '{2}',
TabRightInactiveImage : '{3}',
TabLeftActiveImage : '{4}',
TabLeftInactiveImage : '{5}',
AutoPostBack : {6},
AutoPostBackReference : ""{7}"",
PopupPosition : {8}
}});            
", ClientID
 , Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
	"Karpach.WebControls.Images.SliderHandle.gif")
 , Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
	"Karpach.WebControls.Images.TabRightActive.gif")
 , Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
	"Karpach.WebControls.Images.TabRightInactive.gif")
 , Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
	"Karpach.WebControls.Images.TabLeftActive.gif")
 , Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
	"Karpach.WebControls.Images.TabLeftInactive.gif") 
 , AutoPostBack?"true":"false"
 , Page.ClientScript.GetPostBackEventReference(this,"")
 , (int)PopupPosition
 );

Page.ClientScript.RegisterStartupScript(Page.GetType(), 
	String.Format("InitColorPicker_{0}", ClientID), script, true);
if (!DesignMode && Page.Header != null)
{
    RegisterCSSInclude(Page.Header);
}

Where RegisterCSSInclude is the following helper method:

private void RegisterCSSInclude(Control target)
{
    // CSS                   
    bool linkIncluded = false;
    foreach (Control c in target.Controls)
    {
        if (c.ID == "ControlPickerStyle")
        {
            linkIncluded = true;
        }
    }
    if (!linkIncluded)
    {
        HtmlGenericControl csslink = new HtmlGenericControl("link");
        csslink.ID = "ControlPickerStyle";
        csslink.Attributes.Add("href", Page.ClientScript.GetWebResourceUrl
	(typeof(ColorPicker), "Karpach.WebControls.Styles.ColorPicker.css"));
        csslink.Attributes.Add("type", "text/css");
        csslink.Attributes.Add("rel", "stylesheet");
        csslink.EnableViewState = false;
        target.Controls.Add(csslink);
    }
}

Then I overrode the Render event of WebControl class in order to render the control HTML.

using (PlaceHolder plh = new PlaceHolder())
{
    if (DesignMode || Page.Header == null)
        RegisterCSSInclude(plh);
    Table table = new Table();
    table.CellPadding = 0;
    table.CellSpacing = 0;
    table.Rows.Add(new TableRow());
    table.Rows[0].Cells.Add(new TableCell());
    table.Rows[0].Cells.Add(new TableCell());
    table.Rows[0].Cells.Add(new TableCell());
    table.Rows[0].Cells[1].Style.Add(HtmlTextWriterStyle.PaddingRight, "5px");
    HtmlGenericControl txt = new HtmlGenericControl("input");
    txt.EnableViewState = false;
    txt.Attributes.Add("maxlength", "15");
    txt.Attributes.Add("size", "15");
    txt.Attributes.Add("value", Color);
    txt.Attributes.Add("id", ClientID);
    txt.Attributes.Add("name", UniqueID);
    txt.Attributes.CssStyle.Value = "height:17px;padding:2px;";
    table.Rows[0].Cells[0].Controls.Add(txt);
    HtmlGenericControl colorBar = new HtmlGenericControl("div");
    colorBar.EnableViewState = false;
    colorBar.Attributes.CssStyle.Add(HtmlTextWriterStyle.Height, "21px");
    colorBar.Attributes.CssStyle.Add(HtmlTextWriterStyle.Width, "5px");
    colorBar.Attributes.CssStyle.Add("border", "solid 1px #7f9db9");
    colorBar.Attributes.CssStyle.Add(HtmlTextWriterStyle.BackgroundColor, Color);
    table.Rows[0].Cells[1].Controls.Add(colorBar);
    HtmlInputImage btn = new HtmlInputImage();
    btn.Src = Page.ClientScript.GetWebResourceUrl(typeof(ColorPicker), 
		"Karpach.WebControls.Images.ColorPickerIcon.jpg");
    btn.Attributes.Add("onclick", string.Format("colorPicker_{0}.ShowColorPicker
	(this,document.getElementById('{1}'));return false;", ClientID, ClientID));
    btn.Attributes.CssStyle.Add(HtmlTextWriterStyle.ZIndex, "1");
    HtmlGenericControl container = new HtmlGenericControl("div");
    container.EnableViewState = false;
    container.Controls.Add(btn);
    container.Attributes.CssStyle.Add(HtmlTextWriterStyle.Position, "static");
    container.Attributes.CssStyle.Add(HtmlTextWriterStyle.Display, "block");
    table.Rows[0].Cells[2].Controls.Add(container);
    plh.Controls.Add(table);
    plh.RenderControl(output);
}

There are a few ways how you can save postback value of color picker. However I think the best way is to implement IPostBackDataHandler interface.

public bool LoadPostData(string postDataKey,NameValueCollection postCollection)
{
    String presentValue = Color;
    String postedValue = postCollection[postDataKey];

    if (presentValue == null || !presentValue.Equals(postedValue))
    {
        Color = postedValue;
        return true;
    }
    return false;
}

public virtual void RaisePostDataChangedEvent()
{
    OnColorChanged(EventArgs.Empty);
}

public void OnColorChanged(EventArgs e)
{
    if (ColorChanged != null)
        ColorChanged(this, e);
}

LoadPostData method will be called during each postback, when postback form has token with key this.UniqueID. As you can see above, the rendered input tag has name attribute this.UniqueID.

ColorPicker properties are stored in ControlState by overriding LoadControlState and SaveControlState:

protected override void LoadControlState(object savedState)
{
    Color = (string)(savedState as object[])[0];
    AutoPostBack = (bool)(savedState as object[])[1];
    PopupPosition = (PopupPosition)(savedState as object[])[2];
}

protected override object SaveControlState()
{
    object []saveState = new object[3];
    saveState[0] = Color;
    saveState[1] = AutoPostBack;
    saveState[2] = PopupPosition;
    return (object)saveState;
}

You need to invoke the RegisterRequiresControlState method to register control for participation in control state, otherwise LoadControlState and SaveControlState won't fire.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    Page.RegisterRequiresControlState(this);
}

Build.proj

Now, the final touch: Minification of JavaScript and CSS. I used Yahoo YUI compressor and Microsoft MSBuild. Here is the final MSbuild file:

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <MSBuildCommunityTasksPath>..\References</MSBuildCommunityTasksPath>
    <ProjectName>WebControls</ProjectName>    
  </PropertyGroup>
  <Target Name="Compress">

    <Message Text="Create temp files ..." />
    <Copy SourceFiles=".\$(ProjectName)\Javascript\ColorPicker.js"
        DestinationFiles=".\$(ProjectName)\Javascript\ColorPicker.js.full"/>    
    <Copy SourceFiles=".\$(ProjectName)\Styles\ColorPicker.css"
        DestinationFiles=".\$(ProjectName)\Styles\ColorPicker.css.full"/>    
    <Exec Command=
       "java -jar yuicompressor-2.4.2.jar --type js .\$(ProjectName)\
       Javascript\ColorPicker.js.full >.\$(ProjectName)\Javascript\ColorPicker.js"/>

    <Exec Command=
       "java -jar yuicompressor-2.4.2.jar --type css .\$(ProjectName)\Styles\
       ColorPicker.css.full >.\$(ProjectName)\Styles\ColorPicker.css"/>
  </Target>
  <Import Project=".\References\MSBuild.Community.Tasks.targets" />
  <Target Name="Build" DependsOnTargets="Compress">

    <Message Text="Building Project" />
    <MSBuild Projects="./$(ProjectName)/$(ProjectName).sln"
        Properties="Configuration=Release;Platform=Any CPU" />    
  </Target>
</Project>

Now you even don't need Visual Studio to compile DLL. All that you need is .NET 2.0 installed and then the following console script will do the compilation:

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe  Build.proj /t:Build

Per requests below, I added PopupPosition property, so you can specify position of ColorPicker popup (top left, top right, bottom left, bottom right - default).

I also added AutoPostBack property and ColorChanged event.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Viktar Karpach
Web Developer comScore
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionwebresource not found?memberMillhill25 Nov '12 - 23:06 
Hi,
I like the control very much (nice job!), so I try to use it in my webapp inside an UpdatePanel using VS2010 and framework 4, but i keep getting the error (in IE and Chrome) that 'colorPicker_colpckrAchtergrond' is undefined when clicking the image with these script-code popping-up:
function onclick(event)
{
colorPicker_colpckrAchtergrond.ShowColorPicker(this,document.getElementById('colpckrAchtergrond'));return false;
}
I've done some research and it seems that the webresource with the ColorPicker javascript is not loaded; I don't see any loaded script-block with the ColorPicker javascript functions.
Does anyone know how to get this right. Do I miss something in my web.config ?
AnswerRe: webresource not found?memberViktar Karpach26 Nov '12 - 16:54 
Hi,
 
This control is designed for .NET 2.0. Since .NET 3.5 there were a change in a way how startup scripts are loaded.
 
In ColorPicker.cs
 
Page.ClientScript.RegisterStartupScript(...)
 
should be replaced with
 
ScriptManager.RegisterStartupScript(...)
 
See my post about ScriptManager for more details.
Regards,
Viktar Karpach
 
MCTS .NET 2.0,3.5 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: webresource not found?memberMillhill27 Nov '12 - 0:28 
Thanks for your reply Viktar,
 
The problem was indeed the use within an UpdatePanel with triggers and that therefore a registration with the Page ScriptManager was also needed. After copying (and slightly modify it) the registartion code from the OnPreRender method to my Page Render method (I don't have a VS version installed for 3.5 projects to change / build code in Control itself) and using the ScriptManager.RegisterStartUpScript() method it finally worked fine. I also had to add the CSS registration link code in PageLoad for proper rendering / styling btw.
 
So if someone encounters the same problem, this is a workaround too.
Of course a new version for asp.net 4 would be also very nice to have Wink | ;) .
 
Greetz,
Peter
GeneralMy vote of 5memberiman_fire_man25 Aug '12 - 18:40 
thank for beautiful program
QuestionAnother problem in multiview [modified]memberMember 911628413 Jun '12 - 9:48 
Hello, you've done a great job but i think i found another bug of the control:
 
I'm working in visual studio 2008 with framework 3.5
 
when i put the control inside a multiview that is nested into a updatepanel control the control doesnt display the color palette when picking in the icon.
 
<as:UpdatePanel runat="server">
    <ContentTemplate>
    <asp:Multiview runat="server">
      <asp:View id="view1" runat="server">
      </asp:View>
      <asp:View id="view2" runat="server">
           COLOR PICKER CONTROL
      </asp:View>
   </asp:Multiview>
</asp:UpdatePanel>
 
This problem only happens when you put the color picker control in a different view of the first one, i mean, when you change the view. When the control is in the first view the control works fine.
 
It's a bug or i'm doing something wrong?

modified 13 Jun '12 - 20:48.

BugIssue with control users.memberjosh13jj1317 May '12 - 6:26 
One of my user control contains more of one user controls and this user control contains the update panel and one of the child user control contains the color picker, but for display this child control we need to make some request and steps on our process, when the user control is enable and display the color picker this not works and when I put on the parent user control and this play when the update panel works, I review and is because when is on the child user control not create the script for the ajax something like:
= new ColorPicker({
 
I hope you can help me.
Best Regards,
QuestionColor picker problemmemberlalaaa15 Feb '12 - 0:58 
I used color picker in my web app
<cc1:ColorPicker ID="txtBackColor" runat="server" Color="#FFFFFF" önkeydown="return false" />
when i mouse over on color picker, the picker was expanded. i don't know why and i want fixed that.
can you help me?
AnswerRe: Color picker problemmemberViktar Karpach15 Feb '12 - 4:26 
What browser you are using?
Regards,
Viktar Karpach
 
MCTS .NET 2.0,3.5 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Color picker problemmemberlalaaa18 Feb '12 - 3:04 
I used Firefox and Google chrome.
GeneralRe: Color picker problemmemberlalaaa19 Feb '12 - 21:59 
I use Firefox and Google chrome browsers. Any suggestion to fix the problem,Please?
GeneralMy vote of 5memberDrABELL1 Jul '11 - 17:00 
Very useful article and practical solution, 5*
GeneralMy vote of 5memberAli Al Omairi(Abu AlHassan)18 Apr '11 - 21:59 
100 Rose | [Rose] , man;
this is perfect !!
QuestionColor Picker in IE 9memberanupkumarv6 Apr '11 - 21:46 
Hi,
I found that this color picker is not working correctly in IE 9.
When I tried to access the demo (http://www.karpach.com/ColorPickerDemo.aspx[^]) in IE 9, the result is not as expected. The color is not getting updated once you select a color. Could you please check this and let me know.
AnswerRe: Color Picker in IE 9memberViktar Karpach3 May '11 - 9:09 
Sadly, my site doesn't have latest version of ColorPicker control. This is why you see a bug on demo page. ColorPicker does have a small bug in IE9. However it doesn't affect its functionality. I'll release updated version in a next few days. Then it should be 100% compatible with IE9. I already updated my website with it, so demo should work correctly.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

AnswerRe: Color Picker in IE 9memberViktar Karpach6 May '11 - 10:50 
Fixed. You can download new version from Color Picker Demo Page.
Regards,
Viktar Karpach
 
MCTS .NET 2.0,3.5 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralMy vote of 5memberYalin Meric6 Jan '11 - 3:52 
It is working and has very good interface. Thanks Viktar!
GeneralFew controls on page problem [modified]membereyale6 Jul '10 - 5:44 
Thanks for a really great control! The only problem I’m facing is when there is more than one control on the page, After you change the slider of one of them, the slider of the next isn’t working.
Can this be resolved?
 
thx

modified on Tuesday, July 6, 2010 11:52 AM

GeneralRe: Few controls on page problemmemberViktar Karpach8 Aug '10 - 15:55 
Sorry, it took me so long to fix this bug. See ColorPicker demo page for latest release. Sliders should work fine now.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Few controls on page problem [modified]membereyale12 Aug '10 - 3:40 
Thanks Viktar, works great!

modified on Thursday, August 12, 2010 9:47 AM

QuestionEnhancement in ColorSlidermemberchrigl28 Apr '10 - 22:39 
Awesome Control! Thank you very much for sharing!
 
I added this lines of code at the bottom of the method chooseColorSlider() in the file ColorPicker.js:
 
        
    function chooseColorSlider()
    {
        //[...]
        if (that.AutoPostBack) {
            eval(that.AutoPostBackReference);
        }
    }  
 
This leads to the effect, that the colorSlider will also raise a "ColorChanged" event on the Server.
 
Maybe you can implement this in the next Release?
AnswerRe: Enhancement in ColorSlidermemberViktar Karpach8 Aug '10 - 15:54 
Sorry, it took me so long. I added your suggestion. See ColorPicker demo page for latest release.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralGreat control!memberSandeep Mewara26 Mar '10 - 2:01 
Thumbs Up | :thumbsup:
GeneralGreat control!memberSandeep Mewara13 Mar '10 - 22:54 
5 from me...
When is the next update expected (features n bugs resolved?)
GeneralRe: Great control!memberViktar Karpach4 Apr '10 - 17:27 
I just released new version. See ColorPicker demo home page.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Great control!mentorSandeep Mewara26 Jun '10 - 6:27 
Thumbs Up | :thumbsup:
GeneralProblem when using control inside custom control, then multiple instances of that controlmemberMagick9316 Feb '10 - 21:39 
Hi
 
I'm trying to us your control inside a custom control, then use that custom control 4 times on a page.
 
It renders perfectly, however when trying to set the color in any of the custom control instances will only update the first instance.
 
Is it using ID rather than ClientId?
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid%28VS.71%29.aspx[^]
 
Anyway, thanks for sharing, its an awesome control.
GeneralRe: Problem when using control inside custom control, then multiple instances of that controlmemberViktar Karpach18 Feb '10 - 17:52 
I'll investigate this issue, probably you are right. It is difficult to use ClientID, since chain of IDs is not build yet during server control initialization. However, I might use relative DOM binding (something like onclick="ShowPopup(this)").
 
I'll see what I can do this weekend. Thank you for finding bug.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Problem when using control inside custom control, then multiple instances of that controlmemberMagick9319 Feb '10 - 10:33 
Hi Viktar
 
Dont waste your weekend on it - I fixed it.
 
I'll get the updated code to you soon. Its at work, so I'll probably get it to you on monday.
 
Regards,
Anton
GeneralRe: Problem when using control inside custom control, then multiple instances of that controlmemberViktar Karpach4 Apr '10 - 17:28 
Finally I released new version of ColorPicker. Check ColorPicker home page.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

QuestionAwesome Control! A few bugs? Or just me?memberbjahelka29 Jan '10 - 8:34 
Viktar, this control is totally bitchin. Thanks for taking the time to code it!
 
I'm using multiple ColorPickers on my page. At first it appeared that the PopupPosition property wasn't working, then I found out that if you set ALL of the ColorPicker controls to have the same PopupPosition, then it will work. Wondering why I couldn't select each one independently.
 
The above behavior was noticed because the popup was being cut off on my page. I have these controls on the left side of the page (in a div), and on the right side I have a preview pane with the proposed color changes (also in a div). When the color picker poped up, it would only show in the part of the color picker in the containing div. I thought maybe it had to do with a funky z-order being set somewhere in my css. Couldn't find anything screwy, and besides, the style on this control had a z-order of 10001, so it ~should~ show. If you have any idea on that, I'd like to hear it.
 
Would be great to get this to work with the RegularExpressionValidator. Is there some default property setting that could be implemented with this custom control to make it work with the built in ASP.NET Validators? Or do they just plain not work with custom controls (what about exposing the textbox inside the ColorPicker somehow)?
 
Would be very nice if the sliders would be pre-set to the value that is already in the text box.
 
Click the icon to open the color picker, would be nice if you clicked it again it would close the color picker.
 
I'm going to tackle the last two and see if I can figure out how to make those work and will post code if I figure something out. But the first two are a little beyond what I know to be sure.
 
Thanks again for the wonderful control!
AnswerRe: Awesome Control! A few bugs? Or just me?memberViktar Karpach18 Feb '10 - 17:41 
Thank you for finding bugs. Validators are long time on my list. This a next feature that I'll try to implement. You are right probably the easiest way would be to extend TextBox control.
 
I'll fix PopupPosition property in next release.
 
In regards of z-order. It is really difficult to trace. Check if you div has position: absolute or relative, also overflow:hidden.
 
Features below look less important then bugs and suggestions above. See if you can knock them down yourself.
>> Would be very nice if the sliders would be pre-set to the value that is already in the text box.
>> Click the icon to open the color picker, would be nice if you clicked it again it would close the color picker.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

AnswerRe: Awesome Control! A few bugs? Or just me?memberViktar Karpach4 Apr '10 - 17:29 
Finally I released new version of ColorPicker. Check ColorPicker home page. Validators are now supported.
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralColorPicker in gridview EditItemTemplatememberjudyIsk21 Jul '09 - 22:45 
Hi, Thanx for the nice control.
When i place it just straight on my aspx page - works very nicely, but i need it in my gridview - editItemTemplate and in my FooterTemplate - here the ColorPicker control CRASHES. this is the Javascript Error i get when clicking the button to choose a color:Microsoft JScript runtime error: 'colorPicker' is undefined
is it a bug? can it be fixed?
GeneralRe: ColorPicker in gridview EditItemTemplatememberViktar Karpach23 Jul '09 - 3:36 
Did you use latest version from ColorPicker demo page? I'll try to reproduce an error. Usually I don't use ASP.NET DataGrids, so probably I missed this bug.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: ColorPicker in gridview EditItemTemplatememberjudyIsk25 Jul '09 - 21:14 
Hi, yes. i downloaded:
Download ASP.NET Color Picker v.1.4.10423.1
from the Demo site.
GeneralRe: ColorPicker in gridview EditItemTemplatememberViktar Karpach26 Jul '09 - 12:07 
I build mine GridView example. It works no errors in IE7-8, Firefox 3.5. Take a look GridViewTest_WebControls.zip. May be I am missing something.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralBug in SlidermemberMember 540677930 Jun '09 - 5:20 
I am currently using your project (works great btw) but I noticed a small bug that I thought you may or may not want to fix. On the Slider, if you manually type in a number greater than 255 the knob will continue moving "down the line." For example, try 300 and the knob will show up over the text or try 2555 and the knob is completely gone.
 

I did the following to a function to fix this bug. Feel free to use this or to use a different method.
    function positionSliderImage(e, theIndex, inputObj)
    {
        if (this) inputObj = this;
        if (!theIndex) theIndex = inputObj.getAttribute('sliderIndex');
        var handleImg = document.getElementById('slider_handle' + theIndex);
        var ratio = sliderObjectArray[theIndex]['width'] / (sliderObjectArray[theIndex]['max'] - sliderObjectArray[theIndex]['min']);
        var intValue = parseInt(sliderObjectArray[theIndex]['formTarget'].value, 10);
        var currentValue = intValue - sliderObjectArray[theIndex]['min'];
        if(currentValue > sliderObjectArray[theIndex]['max'])
        {
            currentValue = sliderObjectArray[theIndex]['max'];
            sliderObjectArray[theIndex]['formTarget'].value = currentValue;
        }
        else if (currentValue < sliderObjectArray[theIndex]['min'])
        {
            currentValue = sliderObjectArray[theIndex]['min'];
            sliderObjectArray[theIndex]['formTarget'].value = currentValue;
        }
        else
        {
            sliderObjectArray[theIndex]['formTarget'].value = currentValue;
        }
        handleImg.style.left = currentValue * ratio + 'px';
        setColorByRGB();
    }
 
Other than that I am really pleased with what you wrote. Thanks for your hard work on it.
-Dan Calkins (daniel.m.calkins [at] gmail.com)
GeneralRe: Bug in SlidermemberViktar Karpach1 Jul '09 - 6:44 
Thank you for a bug report. I will include your code in next ASP.NET ColorPicker release. Currently I am waiting for my motherboard RMA come back from Gigabyte, so I am not doing any development at home.
 
Also, I am planing to create ASP.NET validators support in my next release.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralMultiple ColorPickers on same pagememberMember 301469127 Mar '09 - 0:52 
Hi Viktar, I'm using your control - which is very good, and works fine when there is only a single ColorPicker control on a page, however I have an page where I have multiple ColorPicker controls, they all work, but when a ColorPicker is ‘popped’ the icon from another ColorPicker shows through.
 
Also if for instance, I have two ColorPicker controls and I pop the first one, the ‘popped’ window is in the correct place (relative to the clicked ColorPicker control), however if then click the second ColorPicker control, the window is ‘popped’ but in the first windows location, so it isn’t positioned relative to the clicked control.
 
In addition another ‘nice to have’ option would be the ability to specify if the associated textbox could have its background colour set to the selected colour, when selecting pale colours (with a textbox background white) it is difficult to see the coloured text.
GeneralRe: Multiple ColorPickers on same pagememberankit_vyas21 Apr '09 - 18:48 
Did you get fix for this. I am having same problem.
Else control is great and works fine.
GeneralRe: Multiple ColorPickers on same pagememberMember 301469121 Apr '09 - 21:28 
Not yet - it's a shame because it works perfectly when there's only one control per page
GeneralRe: Multiple ColorPickers on same pagememberViktar Karpach22 Apr '09 - 2:34 
I didn't have a chance to fix it. I'll take a look tonight. It should be an easy fix.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Multiple ColorPickers on same pagememberankit_vyas22 Apr '09 - 12:36 
It will be great if you can fix it. I recon it should be small bug as it's really really beautiful.
 
When I show it to my partner they said it can't be free as it's great.
 
If you fix, can you please put comment here that you fixed. Will wait for you.
 
Thanks.
GeneralRe: Multiple ColorPickers on same pagememberViktar Karpach23 Apr '09 - 19:42 
It appeared that this is IE specific problem. It took me some time to solve it. Check ColorPicker demo page for latest release.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

GeneralRe: Multiple ColorPickers on same pagememberankit_vyas25 Apr '09 - 13:12 
It works great now.
 
Thanks Viktar for allocating your time for this error. Smile | :)
GeneralRe: Multiple ColorPickers on same pagememberMember 30146911 May '09 - 0:33 
Thanks Viktar - That's great!!
GeneralValidating the controlmemberMember 124714918 Mar '09 - 23:10 
Hi,
 
Nice control, but it's a pitty that it doesn't work with normal ASP.NET validator controls...
 
Wilco
GeneralVisibilitymemberdherrmann17 Mar '09 - 0:18 
Hi,
I have your control in use the first time.
I do the following:
At start of my page the colorpicker is unvisible. But with a button I do in the click-event:
 
colorpicker1.visible=not colorpicker1.visible (VB-Code)
also:
colorpicker1.backcolor=textbox1.backcolor
 
It doesn't function...
 
regards-
Dietrich
GeneralRe: VisibilitymemberViktar Karpach17 Mar '09 - 3:35 
Hi,
 
You are right. I didn't implement visible and backcolor property. If you want to set or get colorpicker color then use color property. I'll implement both properties in next release. For now you can put colorpicker in PlaceHolder then hide/show PlaceHolder.
 
Regards,
Viktar Karpach
 
MCTS .NET 2.0 Web Application, MCPD Web Developer
ASP.NET C# Technical Blog

QuestionSearch in your websitememberBlumen15 Mar '09 - 0:54 
Hi Victor,
 
How did you implement search in this website? I tried with Live search SearchDataSource, but I did not succeed, page was throwing some proxy error.
 
Regards,
Manu
 
“The thing for you is a burial permit. You have only to speak and I will see that you get it.”

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 6 Apr 2010
Article Copyright 2008 by Viktar Karpach
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid