Validate Text entered for RadDatePicker control

3 posts, 1 answers
  1. Selvaraj
    Selvaraj  avatar
    2 posts
    Member since:
    Apr 2012

    Posted 19 Dec 2012 Link to this post

    Hi,

    I have a RaddatePicker control and Submit button in my screen . If user chooses date from datepicker, have no issues. If user enters some random characters in dateinput, it shows warning on screen. However, onclick of Submit button, form is being submitted. I want to restrict the form submission. This field is not a required field. So adding required field validator will not help me.
    Can anyone please help me in resolving this.

    Thanks,
    Selvaraj.V
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Dec 2012 Link to this post

    Hi,

    One suggestion is that you can handle the OnError event of DateInput and can cancel the form submission. Following is the sample code that I tried to achieve your scenario.

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" DateInput-ClientEvents-OnError="OnError">
    </telerik:RadDatePicker>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

    JS:
    <script type="text/javascript">
        function OnError(sender, args) {
            var err = document.getElementById("HiddenField1");
            err.value = 1;
        }
    </script>

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (HiddenField1.Value != "1")
        {
            //do the action
        }
    }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Selvaraj
    Selvaraj  avatar
    2 posts
    Member since:
    Apr 2012

    Posted 19 Dec 2012 Link to this post

    Thanks a lot. It worked...
Back to Top