I have a RadTextBox and an ASP checkbox.
<telerik:RadTextBox ID="igcWebTxtEvent" runat="server" Skin="Outlook" Width = "530px" CausesValidation="True" Font-Bold="False" ForeColor="DarkSlateGray" >
</telerik:RadTextBox>
<asp:CheckBox ID="chkOmitEvent" runat="server" TextAlign="Left" ToolTip="Omit" OnCheckedChanged="chkOmitEvent_CheckedChanged" />
The design time skin for the RadTextBox is "Outlook". Now when the user clicks on the textbox, the background color of the RadTextBox is changed to LemonChiffon. This is done on the client side through JAVASCRIPT which is attached to the checkbox in the behind code in the page load event.
Behined Code:
chkOmitEvent.Attributes.Add("OnClick", "javascript: return setTextBoxBackgroundColor('" + igcWebTxtEvent.ClientID.ToString() + "','" + chkOmitEvent.ClientID.ToString() + "');");
Client side javascript:
var originalStyle="";
function setTextBoxBackgroundColor(textBoxID, checkBoxID)
{
var TextBox = $find(textBoxID);
var retVal = document.getElementById(checkBoxID).checked;
if(retVal)
{
originalStyle = TextBox.get_styles().EnabledStyle[0];
TextBox.get_styles().EnabledStyle[0] += "background-color: lemonchiffon;";
}
else
TextBox.get_styles().EnabledStyle[0] = originalStyle;
TextBox.updateCssClass();
return true;
}
On the client side everything works like it should, when the the RadTextbox is focused or hovered the color becomes white, which is due to the outlook skin, and otherwise its background color is lemon.
Since this happend at the client side, when the submit button is pressed, there is an event handler on the server side:
All the original values are obtained before postback in the page load event, which happen to be "None".
On Page load before postback:
if (!Page.IsPostBack){
originalEnabledColor = igcWebTxtEvent.EnabledStyle.BackColor; originalFocusedColor = igcWebTxtEvent.FocusedStyle.BackColor ;
originalHoverColor=igcWebTxtEvent.HoveredStyle.BackColor ;
}
protected void chkOmitEvent_CheckedChanged(object sender, EventArgs e)
{
if (chkOmitEvent.Checked)
{
igcWebTxtEvent.EnabledStyle.BackColor=
System.Drawing.Color.LemonChiffon;
igcWebTxtEvent.FocusedStyle.BackColor = originalFocusedColor;
igcWebTxtEvent.HoveredStyle.BackColor = originalHoverColor;
}
else
{
igcWebTxtEvent.EnabledStyle.BackColor = originalEnabledColor;
igcWebTxtEvent.FocusedStyle.BackColor = originalFocusedColor;
igcWebTxtEvent.HoveredStyle.BackColor = originalHoverColor;
}
}
Now the problem is that after the server event is called after postback, all colors become lemon, when hovered/focused. And this behavior propogates since the client side function only sets the enabled color and not the focused/hovered colors. So even when the checkbox is unchecked, the hovered/focused colors remain lemon.
However the "else" part of the if condition (when the skin behavior is restored)
else
{
igcWebTxtEvent.EnabledStyle.BackColor = originalEnabledColor;
igcWebTxtEvent.FocusedStyle.BackColor = originalFocusedColor;
igcWebTxtEvent.HoveredStyle.BackColor = originalHoverColor;
}
works fine when it is restored after a postback. And the main observation is that if I do not add the following two lines:
igcWebTxtEvent.FocusedStyle.BackColor = originalFocusedColor;
igcWebTxtEvent.HoveredStyle.BackColor = originalHoverColor;
the hover/focused background colors remain lemon whereas the enabled style one is the same as the skin which is blue. Because my understanding was setting the enabled style background color sets all background colors as is the case when I am setting it to Lemon but not the case when I am setting it to its original color. Original backcolor also happens to be "None". Which is why I guess this is happening.
This is what I am looking for ideally:
1. When a checkbox is checked, the enabled backcolor becomes lemon however focused/hovered remain white
2. When the the checkbox is unchecked, the original skin behavior is restored.
This has to be handled on both client side and server side due to postbacks. On client side it is working fine. However, on the server side it is not.
Is there any other way of acheiving this? I tried to play around with the style attributes, css attributes on the server side but got nothing to work.
Any help would be greatly appreciated.
Thanks,
Tal