RadDatePicker - Style not updated in viewstate

4 posts, 0 answers
  1. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 02 Sep 2011 Link to this post

    I have a RadDatePicker, and I'm setting the background color on the server side when it contains an invalid value like so:

    dtStartDate.DateInput.Style.Add(HtmlTextWriterStyle.BackgroundColor, "red");


    Then on the client side, I have this handler attached to the ClientEvents-OnValueChanged event of the child DateInput of the RadDatePicker.

    function RemoveInvalidStyle(sender, args)
    {
        sender.get_styles().EnabledStyle[0] = sender.get_styles().EnabledStyle[0].replace("background-color:red;", "");
        sender.get_styles().HoveredStyle[0] = sender.get_styles().HoveredStyle[0].replace("background-color:red;", "");
        sender.get_styles().FocusedStyle[0] = sender.get_styles().FocusedStyle[0].replace("background-color:red;", "");
        sender.updateCssClass();
    }

    This works just fine, they both change the background, but after the client call the background will be reset again on the first postback.  Is this due to that not being persisted in the viewstate?  Or is it being overwritten by the property set on the parent wrapper?
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 08 Sep 2011 Link to this post

    Hello Marbry,

    In order to implement the desired functionality, I recommend that you override the .riError style of the RadInput.
    Please examine the following help topics for additional information:
    Styles
    CSS Skin File Selectors

    I hope this helps.

    Best wishes,
    Mira
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 08 Sep 2011 Link to this post

    I was able to get this to work, just resetting it on the server side in addition to the client.  I just added an else and called,

    dtStartDate.DateInput.Style.Value = "";

    I tried calling the Remove method, but it didn't seem to do anything.  The style was still populated immediately after the call.

    dtStartDate.DateInput.Style.Remove(HtmlTextWriterStyle.BackgroundColor);


    BTW - the first link you listed above is dead.
  4. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 13 Sep 2011 Link to this post

    Hello Marbry,

    I am glad the issue is resolved. Thank you for sharing the solution with the community.
    Here is the correct version of the first link.

    All the best,
    Mira
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top