multiple instances of color picker

Feb 11, 2010 at 1:30 PM

Hi

 

Thanks for releasing this really cool control.

I have small issue with using it - I have control, in which I use the color picker twice.

I then use my control multiple times on the aspx page.

 

I find, that if I, for example change the color in the colorpicker on the last instance of my control, it will update the first - and first only. It seems that there is an id of the control that is hardcoded?

Another way to think of it it - imaging having this control showing in each row of a column in a datagrid - modifying the color in any row would only update the first row.

 

How can I change this behaviour?

Thanks

Feb 11, 2010 at 1:55 PM

Hi

 

I changed the code from using ID to using ClientID and it seems to have fixed the problem.

 

The updated code is:

StringBuilder sb = new StringBuilder();

            sb.Append(string.Format(@"<div style=""display:inline;""><div style=""border:solid 1px #000;width:86px;float:left;""><label style=""display:block;background-color:{0};width:80px;margin:3px;"" id=""{1}"">&nbsp;</label></div>", Color, string.Concat(ClientID, "_input")));
            if (this.AutoPostBack)
            {
                sb.Append(string.Format(@"<img src=""{0}"" alt=""Color Picking"" style=""{4}"" onclick=""showColorPicker(this,document.getElementById('{1}'),document.getElementById('{2}'),{3});return false;""/></div>", PickerImageURL, string.Concat(ClientID, "_input"), string.Concat(ID, "_hiddeninput"), "true", DEFAULT_PICKERIMAGE_STYLE));
            }
            else
            {
                sb.Append(string.Format(@"<img src=""{0}"" alt=""Color Picking"" style=""{4}"" onclick=""showColorPicker(this,document.getElementById('{1}'),document.getElementById('{2}'),{3});return false;""/></div>", PickerImageURL, string.Concat(ClientID, "_input"), string.Concat(ID, "_hiddeninput"), "false", DEFAULT_PICKERIMAGE_STYLE));
            }
            output.Write(sb);