This is a migrated thread and some comments may be shown as answers.

Changing Background Color OnChange

6 Answers 309 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chameleoki
Top achievements
Rank 2
Chameleoki asked on 21 Jun 2008, 06:32 PM
I would like to have the background color of a combo box change when its index is changed (to visually show the user what items have changed in a record).  I tried handling the OnClientSelectedIndexChanged and using this javascript but nothing happens:

<script language="javascript" type="text/javascript">
function OnClientSelectedIndexChanged(sender, eventArgs)
{
 var item = eventArgs.get_item();
 var combo = item.get_comboBox();
 item.setAttribute("BackColor","#FF8080");
}
</script>

I think it might have to do with the animation overriding it but unclear.  I also want to do this with the DatePicker.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jun 2008, 11:43 AM
Hi,

Try setting the backcolor on the server side as shown below.

CS:
 protected void RadComboBox2_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        RadComboBox2.BackColor = System.Drawing.Color.Blue;        
    } 


Shinu.
0
Chameleoki
Top achievements
Rank 2
answered on 23 Jun 2008, 02:36 PM
Thanks, Shinu, but I'm trying to do it via javascript so it doesn't take a postback/ajax.  I have a lot of controls on the page and so that would be a lot of postbacks.

For regular asp controls, such as a textbox I can hook to the OnChange event like so:  OnChange="this.style.backgroundColor='#FF8080'"

Anyone know how to do that for the combobox and DatePicker?
0
Chameleoki
Top achievements
Rank 2
answered on 23 Jun 2008, 03:27 PM
Okay, closer I believe.

I forgot the get_attributes() section so the line is now:

item.get_attributes().setAttribute("backColor","#FF8080");

Still doesn't update it, though.
0
Chameleoki
Top achievements
Rank 2
answered on 23 Jun 2008, 04:01 PM
Still need the answer for the combobox but here's the answer for the datepicker.

Add this to your datepicker declaration:

DateInput-ClientEvents-OnValueChanged="OnClientValueChanged"

Then add this to your <script> block:

function OnClientValueChanged(sender, eventArgs)
{
  sender.get_styles().EnabledStyle[0] += "background-color: #FF8080;";
  sender.updateCssClass(); 
}
0
Veselin Vasilev
Telerik team
answered on 24 Jun 2008, 11:17 AM
Hi Chameleoki,

What about using this code in the OnClientSelectedIndexChanged event handler:

function OnClientSelectedIndexChangedHandler(sender, eventArgs) 
  var comboInput = sender.get_inputDomElement();   
  comboInput.style.backgroundColor = "red";  


Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chameleoki
Top achievements
Rank 2
answered on 24 Jun 2008, 04:57 PM
Awesome!  That worked.  Thank you very much!.  Looks like I should read up on the DomElement.

Every question I have ever had has been answered.  Your support is great!
Tags
ComboBox
Asked by
Chameleoki
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Chameleoki
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or