Field Validation when using Rad Window as Dialog

4 posts, 1 answers
  1. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 22 Mar 2011 Link to this post

    Hi All,

    I have the follow scenario:

    There are 2x RadDateTimePickers on a RadWindow along with a checkbox. When the checkbox is checked they both become enabled.

    I pass the dates back to my main window when the RadWindow is closed. I would like to prevent the RadWindow from closing and alert the user when their values are invalid. Examples: The input fields are enabled, but empty. The second field is larger than the first, etc. 

    The main problem here is that my close function which closes the RadWindow fires before the form validation. I read that to avoid this I should move my close function to server-side, but I am not sure this is a viable solution because I pass arguments back from the RadWindow to the main window.

    How can I fix this?

    Sean

  2. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 23 Mar 2011 Link to this post

    Hello Sean,

    The easiest solution is to add a button that calls a validation function. This is demonstrated in the following demo: http://demos.telerik.com/aspnet-ajax/window/examples/dialogreturnvalue/defaultcs.aspx. Take a look at the Dialog1.aspx page and more specifically the returnToParent() function. The approach is:
    1. validate the user's input
    2. raise a flag accordingly
    3. check the value of the flag
    • if it is OK call the window's Close() method to pass the values to the parent
    • if it isn't you can show an alert or change a label's text, etc.


    All the best,
    Marin
    the Telerik team
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 23 Mar 2011 Link to this post

    Hi Marin,

    Thank you for this solution. It works as I would expect. I alert the user and return rather than closing my window when validation fails. Is there a simple way to stop the RadWindow from flashing when I return from failed validation?

    Sean

    EDIT: I just hooked up ajax to/from my button so only the button refreshes (without flashing at all) when it is pressed and the page doesn't close.
  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 24 Mar 2011 Link to this post

    Hi Sean,

    I am glad your project is going well.

    The flashing could have been caused by the reloading of the contents, but I see that you have worked around that.


    Greetings,
    Marin
    the Telerik team
Back to Top