ColorPickerExtender fails when using SelectedColorhttp://forums.asp.net/t/1476608.aspx/1?ColorPickerExtender+fails+when+using+SelectedColorThu, 21 Apr 2011 09:17:27 -040014766083434302http://forums.asp.net/p/1476608/3434302.aspx/1?ColorPickerExtender+fails+when+using+SelectedColorColorPickerExtender fails when using SelectedColor <p>Colorpickerextender stops working when I set SelectedColor. Is this a bug or am I doing something wrong?</p> <p><br> </p> <p>&lt;asp:Label ID=&quot;Label1&quot; Text=&quot;Color&quot; runat=&quot;server&quot; /&gt;<br> &nbsp;&nbsp;&nbsp; &lt;asp:TextBox ID=&quot;TextBox1&quot; runat=&quot;server&quot; /&gt;<br> &nbsp;&nbsp;&nbsp; &lt;ajaxToolkit:ColorPickerExtender runat=&quot;server&quot; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID=&quot;ColorPickerExtender1&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TargetControlID=&quot;TextBox1&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SampleControlID=&quot;Label1&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SelectedColor=&quot;000000&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OnClientColorSelectionChanged=&quot;colorChanged&quot; /&gt;</p> <p><br> </p> <p>&lt;script type=&quot;text/javascript&quot;&gt;<br> &nbsp;&nbsp;&nbsp; function colorChanged(sender) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.get_element().style.color = &quot;#&quot; &#43; sender.get_selectedColor();<br> &nbsp;&nbsp;&nbsp; }<br> &lt;/script&gt;</p> <p><br> </p> 2009-09-30T22:46:58-04:003434697http://forums.asp.net/p/1476608/3434697.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>&nbsp;Try referring here</p> <p><a href="http://www.aspsnippets.com/post/2009/05/16/AJAX-Control-Toolkit-Color-Picker-Control-in-ASPNet.aspx">http://www.aspsnippets.com/post/2009/05/16/AJAX-Control-Toolkit-Color-Picker-Control-in-ASPNet.aspx</a></p> 2009-10-01T05:36:17-04:003434869http://forums.asp.net/p/1476608/3434869.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>no that didnt help. I dont have any problems getting it to work UNTIL i add SelectedColor. Anyone else having this problem? I tried to exchange the label to a div in my code thinking that could it, but without luck. Try it yourself.</p> <p><br> </p> <p>Thanks<br> </p> 2009-10-01T07:22:02-04:003435374http://forums.asp.net/p/1476608/3435374.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>no? Can I get confirmation that this is working for some people? Today I downloaded the new toolkit release and it still doesnt work for me. I must be doing something wrong but there isnt much to play with. I created a new page with the above code for testing purpose, it works fine until I add SelectedColor.</p> <p>some feedback please, thanks.<br> </p> 2009-10-01T11:15:51-04:003438566http://forums.asp.net/p/1476608/3438566.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>I guess it's working for everyone else. Someone please say SelectedColor is working for you and please post the most simple example possible where this is working so that I know Im doing something wrong. I cant get it to work but noone seems to have this problem but me. :(<br> </p> 2009-10-03T11:03:13-04:003442754http://forums.asp.net/p/1476608/3442754.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>Hi Boddam,</p> <p>After debugging the design code in the debug mode, I found that the ColorPickerBehavior has stored the color validation Regex in a &quot;static&quot; object in its initialize function. </p> <pre class="prettyprint">initialize: function() { AjaxControlToolkit.ColorPickerBehavior.callBaseMethod(this, 'initialize'); // Store the color validation Regex in a &quot;static&quot; object off of // AjaxControlToolkit.ColorPickerBehavior. If this _colorRegex object hasn't been // created yet, initialize it for the first time. if (!AjaxControlToolkit.ColorPickerBehavior._colorRegex) { AjaxControlToolkit.ColorPickerBehavior._colorRegex = new RegExp('^[A-Fa-f0-9]{6}$'); } var elt = this.get_element(); $addHandlers(elt, this._element$delegates); if (this._button) { $addHandlers(this._button, this._button$delegates); } var value = this.get_selectedColor(); if (value) { this.set_selectedColor(value); } this._restoreSample(); },</pre> <P><BR>This Regex is to validate the SelectedColor property when it is assigned. </P><pre class="prettyprint"> set_selectedColor: function(value) { if (this._selectedColor !== value &amp;&amp; this._validate(value)) { this._selectedColor = value; this._selectedColorChanging = true; if (value !== this._textbox.get_Value()) { this._textbox.set_Value(value); } this._showSample(value); this._selectedColorChanging = false; this.raisePropertyChanged("selectedColor"); } },</pre> <P><BR>But when the SelectedColor property is set in the ColorPickerBehaviors create process, the initialize function has not been fired. Thus, the exception AjaxControlToolkit.ColorPickerBehavior._colorRegex is undefined. would be raised.</P> <P>We need to add the same code about defining the Regex when the page is in the init stage.</P><pre class="prettyprint">&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestSelectedColor.aspx.cs" Inherits="SoluTest_ColorPicker.TestSelectedColor" %&gt; &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" /&gt; &lt;asp:Label ID="Label1" Text="Color" runat="server" /&gt; &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt; &lt;asp:TextBox ID="TextBox1" runat="server" /&gt; &lt;cc1:ColorPickerExtender ID="ColorPickerExtender1" runat="server" Enabled="True" PopupButtonID="Button1" SelectedColor="33ffcc" TargetControlID="TextBox1" SampleControlID="Label1" OnClientColorSelectionChanged="colorChanged"&gt; &lt;/cc1:ColorPickerExtender&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; //This code must be placed below the ScriptManager, otherwise the "Sys" cannot be used because it is undefined. Sys.Application.add_init(function() { // Store the color validation Regex in a "static" object off of // AjaxControlToolkit.ColorPickerBehavior. If this _colorRegex object hasn't been // created yet, initialize it for the first time. if (!AjaxControlToolkit.ColorPickerBehavior._colorRegex) { AjaxControlToolkit.ColorPickerBehavior._colorRegex = new RegExp('^[A-Fa-f0-9]{6}&#36;'); } }); function colorChanged(sender) { sender.get_element().style.color = "#" + sender.get_selectedColor(); } &lt;/script&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><br> If my suggestion can make sense, I recommend that you post this issue to the IssueTracker of the CodePlex to get further help and make sure whether this is a design issue or not.<br> <a href="http://www.codeplex.com/AjaxControlToolkit/WorkItem/AdvancedList.aspx">http://www.codeplex.com/AjaxControlToolkit/WorkItem/AdvancedList.aspx</a></p> <p>Best regards,</p> <p>Zhi-Qiang Ni</p> 2009-10-06T08:49:48-04:003445308http://forums.asp.net/p/1476608/3445308.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>amazing! thank you for taking time to figure this out. :)<br> </p> 2009-10-07T11:33:58-04:003812367http://forums.asp.net/p/1476608/3812367.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>Hi&nbsp;all,</p> <p>I tried to set the&nbsp;ajax colorpicker SelectedColor&nbsp;property in the code behind, and I'm getting the same error.</p> <p>&nbsp;</p> <p>I tried to add this js code as recommended above:</p> <p><font size="2"><pre class="prettyprint">Sys.Application.add_init(function() { // Store the color validation Regex in a &quot;static&quot; object off of // AjaxControlToolkit.ColorPickerBehavior. If this _colorRegex object hasn't been // created yet, initialize it for the first time. if (!AjaxControlToolkit.ColorPickerBehavior._colorRegex) { AjaxControlToolkit.ColorPickerBehavior._colorRegex = new RegExp('^[A-Fa-f0-9]{6}$'); } });</pre> </p> <p><br> </font>&nbsp;</p> <p></p> <p>But now I'm getting the error &quot;AjaxControlToolkit&quot; is not defined.</p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">Can anyone help?!</font></p> 2010-04-30T10:36:26-04:003814722http://forums.asp.net/p/1476608/3814722.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Tibyan</h4> <p></p> <p>Hi&nbsp;all,</p> <p>I tried to set the&nbsp;ajax colorpicker SelectedColor&nbsp;property in the code behind, and I'm getting the same error.</p> <p><br> </p> <p>I tried to add this js code as recommended above:</p> <p><font size="2"></font></p> &lt;div class=&quot;dp-highlighter&quot;&gt;&lt;div class=&quot;bar&quot;&gt;&lt;div class=&quot;tools&quot;&gt;<a href="#">view plain</a><a href="#">copy to clipboard</a><a href="#">print</a><a href="#">?</a><br> &lt;/div&gt;&lt;/div&gt; <ol class="dp-c" start="1"> <li class="alt"><span><span>&lt;font&nbsp;size=</span><span class="string">&quot;2&quot;</span><span>&gt;&nbsp;&nbsp;&nbsp;&nbsp;Sys.Application.add_init(function()&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Store&nbsp;the&nbsp;color&nbsp;validation&nbsp;Regex&nbsp;in&nbsp;a&nbsp;&quot;static&quot;&nbsp;object&nbsp;off&nbsp;of&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;AjaxControlToolkit.ColorPickerBehavior.&nbsp;&nbsp;If&nbsp;this&nbsp;_colorRegex&nbsp;object&nbsp;hasn't&nbsp;been&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;created&nbsp;yet,&nbsp;initialize&nbsp;it&nbsp;for&nbsp;the&nbsp;first&nbsp;time.&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(!AjaxControlToolkit.ColorPickerBehavior._colorRegex)&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AjaxControlToolkit.ColorPickerBehavior._colorRegex&nbsp;=&nbsp;<span class="keyword">new</span><span>&nbsp;RegExp(</span><span class="string">'^[A-Fa-f0-9]{6} <p><br> </p> </span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;&lt;/font&gt;&nbsp;&nbsp;</span></li></ol> &lt;/div&gt;<pre class="prettyprint">Sys.Application.add_init(function() { // Store the color validation Regex in a &quot;static&quot; object off of // AjaxControlToolkit.ColorPickerBehavior. If this _colorRegex object hasn't been // created yet, initialize it for the first time. if (!AjaxControlToolkit.ColorPickerBehavior._colorRegex) { AjaxControlToolkit.ColorPickerBehavior._colorRegex = new RegExp('^[A-Fa-f0-9]{6} <p></p> <p></p> ); } });</pre> <p><font size="2"><br> </font>&nbsp;</p> <p>But now I'm getting the error &quot;AjaxControlToolkit&quot; is not defined.</p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">Can anyone help?!</font></p> <p></p> </blockquote> <p></p> <p><br> </p> <p>Did u put it inside script tags? <span><span>&lt;</span><span>script</span><span>&nbsp;</span><span>type</span><span>=</span><span>&quot;text/javascript&quot;</span><span>&gt;</span><span>&nbsp; &lt;/script&gt;<br> </span></span></p> 2010-05-02T18:20:52-04:003870644http://forums.asp.net/p/1476608/3870644.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>It worked thanks <img src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-surprised.gif" alt="Surprised" title="Surprised" border="0"></p> 2010-05-25T10:00:25-04:004391606http://forums.asp.net/p/1476608/4391606.aspx/1?Re+ColorPickerExtender+fails+when+using+SelectedColorRe: ColorPickerExtender fails when using SelectedColor <p>I made some minor changes, and now it works</p> <pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; //This code must be placed below the ScriptManager, otherwise the &quot;Sys&quot; cannot be used because it is undefined. Sys.Application.add_init(function () { // Store the color validation Regex in a &quot;static&quot; object off of // AjaxControlToolkit.ColorPickerBehavior. If this _colorRegex object hasn't been // created yet, initialize it for the first time. if (!Sys.Extended.UI.ColorPickerBehavior._colorRegex) { Sys.Extended.UI.ColorPickerBehavior._colorRegex = new RegExp('^[A-Fa-f0-9]{6}$'); } }); &lt;/script&gt;</pre> <p>&nbsp;</p> 2011-04-21T09:17:27-04:00