Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > Forcing temporary Invalid state or style after postback?
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Forcing temporary Invalid state or style after postback?

Feed from this thread
  • Posted on May 29, 2008 (permalink)

    Hi,

    Using a RadDatePicker from v2008.1.515.20, I need some help in order to achieve the desired functionality with the RadDateInput.

    Three questions if I may:
    1) When the user enters an invalid date, the DateInput it set to InvalidStyle. But after a postback, the DateInput is blank and the InvalidStyle is gone. Is there a way to let it remain in the InvalidStyle until new text is inputed?

    2) After some server-side validation, I may decide that a certain date is invalid (even though it is a date). Is there a way to temporary force the InvalidStyle on a RadDateInput until the control regains the focus. It would then revert to its normal behaviour. I see it as something that would say : "Hey, look HERE to fix your problem!"

    3) I tried solving #2 by setting the EmptyMessageStyle.CssClass to my error class and calling DateInput.Clear(), but I noticed that the EmptyMessageStyle is only displayed when the DateInput is filled with a space, not when it's really empty .

    Setting the EmptyMessage to a single white space forces the EmptyMessageStyle to be applied, but is that the intended behaviour?

    Thank you for your much appreciated support.

    Dominic.

  • Plamen Peshev Plamen Peshev admin's avatar

    Posted on Jun 3, 2008 (permalink)

    Hello,

    Up to your questions

    1) Unfortunately this functionality is not supported in the current version of RadDateInput control - we will forward your request to our developers for further consideration.

    2) and 3) The following code example demonstrates how to force the InvalidStyle on a RadDateInput until the control regains the focus

            <div> 
                <script type="text/javascript"
                function Focus(sender, args) 
                { 
                 
                    var eventArgs = new Telerik.Web.UI.InputErrorEventArgs( 
                                        Telerik.Web.UI.InputErrorReason.ParseError, 
                                        null, 
                                        null, 
                                        null); 
                     
                    sender.raise_error(eventArgs);         
                } 
                </script>       
                   
                <telerik:RadDateInput InvalidStyleDuration="3000" ID="RadDateInput1" runat="server"
                    <ClientEvents OnFocus="Focus"  /> 
                </telerik:RadDateInput> 
            </div> 






    Regards,
    Plamen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Charles avatar

    Posted on Jun 3, 2008 (permalink)

    This is a big problem for us; we need the form to give the user a heads-up upon postback to indicate that an invalid date was entered.  The invalid date here isn't saved anywhere that we can find - is there a way in codebehind to determine if the RadDateTimePicker has an invalid value assigned, and what that value is, so that an error message can be popped up?

  • Posted on Jun 3, 2008 (permalink)

    Thanks for the answers. Three more things :

    1) Like Charles, I'd like to have the possibility to give a message to my users that would go something like this : "the date [user entered date here] is not valid, please choose a date between .... ". Having access to whatever invalid input the user entered as a date is helpful to build an error message.

    2) I tried your code to force the InvalidStyle. With InvalidStyleDuration="3000", it stays in that state for 3 seconds, without it, it only blinks though InvalidStyle. How can I make it last indefinitely, until the user actively gives the focus to the DateInput?

    Here's the code I used:
    function SetInputInvalidState(sender, args)  
    {  
        var eventArgs = new Telerik.Web.UI.InputErrorEventArgs( 
                            Telerik.Web.UI.InputErrorReason.ParseError, 
                            null
                            null
                            null); 
        sender.raise_error(eventArgs); 
    }

    Sys.Application.add_load(function() { var rdtpEnd = $find("<%= rdtpEnd.ClientID %>"); SetInputInvalidState(rdtpEnd.get_dateInput(), null); });

    3) I tried finding documentation on Telerik.Web.UI.InputErrorEventArgs but to no avail. Where can I find documentation about its parameters and functionnality ?

    Thanks,

    Dominic.

  • Charles avatar

    Posted on Jun 4, 2008 (permalink)

    I ended up going with the following:

    1.  Adding a ClientEvents element to my DateInput, setting the OnError client event.
                    <rad:RadDateTimePicker ID="dateTimeExpirationDate" runat="server" FocusedDate="" 
                        dateformat="MM/dd/yyyy HH:mm" DbSelectedDate='<%# DataBinder.Eval( Container, "DataItem.ExpirationDate") %>'>  
                        <DateInput ID="dateInputExpDate" runat="server" DateFormat="MM/dd/yyyy HH:mm">  
                            <ClientEvents OnError="OnExpirationDateError" /> 
                        </DateInput> 
                        <TimeView ID="timeViewExpirationDate" runat="server" TimeFormat="HH:mm">  
                        </TimeView> 
                        <DatePopupButton></DatePopupButton>  
                        <TimePopupButton></TimePopupButton>  
                    </rad:RadDateTimePicker> 


    2.  Adding a Hidden Field to store the entered date.
    <asp:HiddenField ID="hiddenExpirationDate" runat="server" /> 


    3.  Adding the client script to support the OnError.
    <script type="text/javascript">     
    function OnExpirationDateError(sender, args)     
    {     
        var hiddenField = document.getElementById('<%= this.hiddenExpirationDate.ClientID %>');     
        hiddenField.value = args.InputText;  
    }     
    </script> 


    4.  Adding a CustomValidator to validate on empty text.
    <asp:CustomValidator ID="checkExpirationDateFormat" OnServerValidate="ValidateExpirationDateFormat" ValidateEmptyText="true" 
                        ControlToValidate="dateTimeExpirationDate" Text="*" runat="server" ErrorMessage="Expiration date is invalid (mm/dd/yyyy hh:mm)."></asp:CustomValidator> 

    5.  Writing the associated method to validate the Expiration date.

            protected void ValidateExpirationDateFormat(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)  
            {  
                if (!string.IsNullOrEmpty(args.Value))  
                {  
                    DateTime expirationDate = DateTime.MinValue;  
                    args.IsValid = DateTime.TryParseExact(  
                        args.Value,  
                        "yyyy-MM-dd-HH-mm-ss",  
                        CultureInfo.CurrentCulture,  
                        DateTimeStyles.None,  
                        out expirationDate);  
                }  
                else  
                {  
                    if (!string.IsNullOrEmpty(hiddenExpirationDate.Value))  
                    {  
                        if (!checkExpirationDateFormat.ErrorMessage.Contains(hiddenExpirationDate.Value))  
                            checkExpirationDateFormatcheckExpirationDateFormat.ErrorMessage = checkExpirationDateFormat.ErrorMessage + "  Value entered was:  " + hiddenExpirationDate.Value;  
                        else  
                            hiddenExpirationDate.Value = string.Empty;  
                        args.IsValid = false;  
                    }  
                }  
            } 

    Notes:
    This expiration date field can be blank, but if the user enters a value, and it is not correct, I want to be able to tell them and prevent further execution.  This code looks for something in the hidden field; if it is there, it indicates that there was a problem and the appropriate message is displayed.

    For some reason, the validation method fires more than once.  Hence, the code that checks to see if the value entered is already present within the error message.

  • Posted on May 22, 2009 (permalink)

    Hi,

    Can you tell me if the feature requested in this thread has been implemented? Using v2009.1.402.35, I still have the same issues.

    Thanks a lot,

    Dominic.

  • Dimo Dimo admin's avatar

    Posted on May 25, 2009 (permalink)

    Hi Dominic,

    I am afraid this feature has not been implemented, as it has been evaluated as low priority, at least for now.

    Here is how to trigger an Error Style for a RadInput textbox with Javascript :

    http://www.telerik.com/community/forums/aspnet-ajax/input/radnumeric-asp.aspx#720556

    (basically, you need to set  the _invalid client property of the DateInput to true and call updateCssClass() )

    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.

  • Siward Land avatar

    Posted on Feb 24, 2011 (permalink)

    Hi All,

    I am experiencing the same problem as this post and I am using v2010.1.309.35.

    I managed to solve problem 2) in the first post by using reflection.  The below code returns the invalidDateString from codebehind:

    string RadDatePicker1_Text = (string) RadDatePicker1.DateInput.GetType().GetField("invalidDateString", BindingFlags.Instance, BindingFlags.NonPublic).GetValue(RadDatePicker1.DateInput);

    Unfortunately, I couldn't solve 1).  How do I stop RadDateInput from clearing itself after each postback?

  • Radoslav Radoslav avatar

    Posted on Mar 2, 2011 (permalink)

    Hello Siward,

    The RadDateTimePicker does not support the desired functionality, however you could try manually to set the invalid text to the date input control after postback. For example:
    On page load you could get the invalid text and pass it to the client side function::
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(RadDateTimePicker1.InvalidTextBoxValue))
            {
                string script = string.Format("setInvalidText('{0}')", RadDateTimePicker1.InvalidTextBoxValue);
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetInvalidText", script, true);
            }
        }

    The setInvalidText function could get the date time inputs and set the invalid value to them:
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function setInvalidText(text)
                {               
                    setTimeout(function ()
                    {
                        var radDateTimePicker =  $find("<%= RadDateTimePicker1.ClientID %>");
                        var input = radDateTimePicker.get_dateInput();
                        input.set_value(text);
                        input._textBoxElement.value = text;
                    },100);
                }
            </script>
        </telerik:RadCodeBlock>

    Additionally I am sending you a simple example, please check it out and let me know if it helps you.

    Best wishes,
    Radoslav
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
    Attached files

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > Forcing temporary Invalid state or style after postback?