Unable to change background color

3 posts, 1 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 23 Dec 2014 Link to this post

    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. Answer
    Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 29 Dec 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 29 Dec 2014 in reply to Eyup Link to this post

    Eyup,
    Thanks a lot.  Problem solved.

Back to Top