This is a migrated thread and some comments may be shown as answers.

Field Validation when using Rad Window as Dialog

3 Answers 171 Views
Window
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 22 Mar 2011, 08:58 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 23 Mar 2011, 02:38 PM
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
0
Sean
Top achievements
Rank 2
answered on 24 Mar 2011, 12:00 AM
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.
0
Marin Bratanov
Telerik team
answered on 24 Mar 2011, 03:20 PM
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
Tags
Window
Asked by
Sean
Top achievements
Rank 2
Answers by
Marin Bratanov
Telerik team
Sean
Top achievements
Rank 2
Share this question
or