DateInput border with InvalidStyle and RequiredFieldValidator

4 posts, 0 answers
  1. Heinz
    Heinz avatar
    20 posts
    Member since:
    Mar 2008

    Posted 19 Jun 2009 Link to this post

    Datum 2&nbsp;<asp:RequiredFieldValidator ID="rfv2" ControlToValidate="RadDatePicker2" runat="server" 
                     ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>   <br /> 
                <telerik:RadDatePicker ID="RadDatePicker2" runat="server" DateInput-InvalidStyle-BackColor="Red"   > 
                    <DateInput runat="server" CausesValidation="True" > 
                    <InvalidStyle BackColor="Red" /> 
                    </DateInput> 
                </telerik:RadDatePicker> 
    Hi,
    I need RadDatePicker with RequiredFieldValidator. Submitting with no Date shows the errorMessage from RequiredFieldValidator. But I expected to get a red border for DateInput too (InvalidStyle ...). But nothing happens. Whats running wrong?

    Heinz
  2. Dimo
    Admin
    Dimo avatar
    8457 posts

    Posted 19 Jun 2009 Link to this post

    Hello Heinz,

    The RadDatePicker's textbox (which is a RadDateInput control) shows its invalid style only if the user enters something, which cannot be parsed to a valid date. I am afraid that integration between RadDateInput and RequiredFieldValidator, which could exhibit the desired behavior, does not exist.

    However, you can use a CustomValidator and trigger the picker's dateinput invalid style manually. Here is a similar example for RadTextBox that will give you an idea what needs to be done:

    http://www.telerik.com/community/forums/aspnet-ajax/input/showing-error-style-programmatically.aspx

    Greetings,
    Dimo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2009 Link to this post

    Hello Heinz,

    You can also try the approach by attaching clientclick event for button and check whether the user entered something in RadDatePicker, if yes set the invalid style manually .

    ASPX:
     
    <asp:RequiredFieldValidator ID="rfv2" ControlToValidate="RadDatePicker2" runat="server" 
        ErrorMessage="RequiredFieldValidator" ></asp:RequiredFieldValidator> 
     
    <telerik:RadDatePicker ID="RadDatePicker2" runat="server" DateInput-InvalidStyle-BackColor="Red"   >  
        <DateInput ID="DateInput1" runat="server" >  
        <InvalidStyle BackColor="Red" />  
        </DateInput>  
    </telerik:RadDatePicker> 
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ValidatePicker();" OnClick="Button1_Click" />  
     

    JavaScript:
     
    <script type="text/javascript"
    function ValidatePicker() 
        var datepicker = $find("<%= RadDatePicker2.ClientID %>"); 
        if(datepicker.get_selectedDate()==null
        { 
            datepicker.get_dateInput()._textBoxElement.style.border= "red 1px solid";   
        } 
    </script> 

    Thanks,
    Princy.
  4. Heinz
    Heinz avatar
    20 posts
    Member since:
    Mar 2008

    Posted 19 Jun 2009 Link to this post

    The javascript solution works.
    Thanks a lot.
    Greetings
    Heinz
Back to Top