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

Unable to change background color

2 Answers 150 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 24 Dec 2014, 03:34 AM
I have this RadDatePicker:

<tr>
 <td class="auto-style1">Birth Date: *</td>
 <td class="auto-style2">
   <
telerik:RadDatePicker ID="RadDatePicker1" runat="server" Culture="it-IT" MaxDate="2015-12-31" MinDate="1920-01-01">
 </telerik:RadDatePicker>
 <asp:RequiredFieldValidator runat="server" ID="datevalidator" ControlToValidate="RadDatePicker1" Display="Dynamic" ForeColor="#FF3300" ErrorMessage="Enter a date!">
</asp:RequiredFieldValidator>
 </td>
</tr>

and I call this JS
<asp:Panel ID="Panel1" runat="server">
 <script type="text/javascript">
 function ageProb() {
 var DatePicker1 = $find("<%= RadDatePicker1.ClientID %>");
 DatePicker1.get_dateInput()._textBoxElement.style.backgroundColor = "yellow";
 DatePicker1.get_dateInput().focus();
 }
 </script>
</asp:Panel>

With this line of code:
ScriptManager.RegisterStartupScript(this, GetType(), "ageProb", "ageProb();", true);

I have two problems with the above:

1)
I had to put the JS in the body section otherwise I get an error saying: "Impossible to modify the Controls collection because the control contains code blocks (like <% ... %>)".

2) The JS script does not have effect on the RadDatePicker, I mean the background color does not change and I do not get the focus either.

How can I change the background color and get the focus on the RadDatePicker?

Thanks for supporting



2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 29 Dec 2014, 09:45 AM
Hi Felice,

You can achieve this requirement directly on server-side:
protected void Button1_Click(object sender, EventArgs e)
{
    RadDatePicker1.DateInput.BackColor = System.Drawing.Color.Yellow;
    RadDatePicker1.Focus();
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Felice
Top achievements
Rank 1
answered on 29 Dec 2014, 02:27 PM
Eyup,
Thanks a lot.  Problem solved.

Tags
Calendar
Asked by
Felice
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Felice
Top achievements
Rank 1
Share this question
or