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

Javascript cannot change background-color of RadMaskedTextBox in RadGrid

2 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 11 Jun 2011, 12:21 AM
I have a template column in a RadGrid that has a RadMaskedTextBox in it.

When the user selects a row, the entire row is changed color except for these RadMaskedTextBoxes.

I want to change their background color to red when the user selects the row.

I trigger an event to do this with the following in the ClientSettings section of the RadGrid HTML.

 

<ClientEvents OnRowSelected="OnRowSelected" />

The javascript event handler is:

function OnRowSelected(sender, eventArgs) {
    var MasterTable;
    var aryAllRows;
    var rowOneRow;
    var txtItemUPC;
    MasterTable = sender.get_masterTableView();
    aryAllRows = MasterTable.get_dataItems();
    rowOneRow = aryAllRows[eventArgs.get_itemIndexHierarchical()];
    txtItemUPC = rowOneRow.findControl('txtItemUPC');
    txtItemUPC.get_styles().EnabledStyle[0] += "background-color: Red";
}

I can check txtItemUPC.get_value() to see that txtItemUPC is correctly set to the RadMaskedTextBox.

The value of txtItemUPC.get_styles().EnabledStyle[0] is changed by the above code.  However, the RadMaskedTextBox doesn't display any differently.

As a test, I set txtItemUPC.get_styles().EnabledStyle[0] to a garbage value and not receive any error messages.

Can you point out what I am doing wrong?  Note that there is no set_styles option, I believe.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jun 2011, 10:02 AM
Hello John,

Try setting "updateCssClass()" after setting the background color.

Javascript:
txtItemUPC.get_styles().EnabledStyle[0] += "background-color: Red";
txtItemUPC.updateCssClass();

Thanks,
Princy.
0
John
Top achievements
Rank 1
answered on 13 Jun 2011, 08:03 PM
Thanks - that worked.

One more point. Some of the txtItemUPC's have readonly set to true.  This prevents the style change from taking place.

In Javascript, I can enable and disabled a txtItemUPC by changing the value of the _enabled property.  Is there a way to turn readonly on and off?  The only thing I can see about readonly is the function isReadOnly() which can tell you what the value is, but not be used to change it.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or