I have a "ColorPicker" feature in an ASP.NET page similar to this one, except that the shades on the right are dynamically populated depending on whether a shade has already been used or not.
I have a TextBox which shows the hex value (#RRGGBB) of the color/shade selected:
<asp:TextBox runat="server" ID="TbxColorhex" Text="#FF0000" Enabled="false" />
which is rendered as:
<input name="TbxColorhex" type="text" value="#FF0000" id="TbxColorhex"></input>
I am using JavaScript to change the text (hex value) in the TextBox when a shade (table cell) is clicked.
function selectShade(shadehex) {
if (shadehex) {
document.getElementById('divpreview').style.background = shadehex;
document.getElementById('<%= TbxColorhex.ClientID %>').value = shadehex;
}
}
I have a button to Confirm the selected color:
<asp:Button ID="BtnSelectColor" runat="server" Text="Select Color" OnClick="BtnSelectColor_Click" style="margin: 0 auto" />
which triggers this method (on Code behind) when clicked:
protected void BtnSelectColor_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(TbxColorhex.Text))
{
Response.Redirect(Page.ResolveClientUrl("~/Something/AddProject.aspx?projcolor=" + TbxColorhex.Text));
}
}
The Problem:
When a shade is clicked, JavaScript changes the text in the TextBox appropriately (you can see the text in the TextBox changing. However, if I use a debugger I notice that there is no change in the value of the value attribute in the input tag. Therefore, when I click the button it does not get the text that the TextBox displays.
EventArgs ecan you see if there is e.text or something of that nature when debugging..? from the onChange of the TextBox..not the button keep in mind that Buttons triggerPostBacksso you may want to write a javascript function that uses the__DoPostBack(the name of the textbox, false);then on that particular event whether it's OnChange or Exit , onBlur etc.. then see if you can capture it there