I have unusual problem with AJAX toolkit ColorPickerExtender. Javascript code works fine it changes backgound color of extended textbox to picked color and text to picked color code also, but when I try to grab text of that Extended textBox from codebehind it return like it returns initial Text Value like javascript didn’t change it. Since this same code works on my other application I suspect that the problem is that I put ColorPickerExtender in UpdatePanel and then in User Control.Here is the code:
User Control Code where ColorPickerExtender is:
<script language="javascript" type="text/javascript">
function colorChanged(sender) {
sender.get_element().style.backgroundColor = "#" + sender.get_selectedColor();
sender.get_element().style.color = "#" + sender.get_selectedColor();
sender.get_element().value = "0x" + sender.get_selectedColor();
}
</script>
...
...
<asp:TextBox ID="ColorTextBox" runat="server" ReadOnly="True" BackColor="Black" Text="" >0x000000</asp:TextBox>
<asp:ColorPickerExtender ID="ColorTextBox_ColorPickerExtender" runat="server" Enabled="True" TargetControlID="ColorTextBox" OnClientColorSelectionChanged="colorChanged" PopupButtonID="PickColorButton">
</asp:ColorPickerExtender>
<asp:Button ID="PickColorButton" runat="server" Text="Pick Color" />
Page Code (Upper user control is wrapped in Panel and than update panel):
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="PostNewThoughtButton1" PopupControlID="pnlThoghtPopup" BackgroundCssClass="modalBackground" DropShadow="false" />
...
<asp:Panel ID="pnlThoghtPopup" runat="server" Style="display:none;">
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<ContentTemplate>
<My:NewThoughtPopup ID="NewThoughtPopup1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
So when I try to call this in codebehind:
string color = ColorTextBox.Text;
color always returns inital value of: 0x000000 altought everything seems fine from client side ColorTextBox text gets updated and it’s color changed,nothing happens on server side, do I have to call postback before trying to get string color? Note: same code works fine without update panel and when not using it on user control
I had a similar problem – it’s because the TextBox is set to
ReadOnly="True"you can use a HiddenField additionally to your TextBox
and in javascript just set the value of the HiddenField with
because you set the value of the HiddenField in Javascript and you want this value again on PostPack you need to set it again on
Page_Loadwith