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

[Solved] Client validation not working with window loaded from form

1 Answer 78 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aaron
Top achievements
Rank 1
Aaron asked on 02 Feb 2012, 01:40 AM
I have been able to get the examples provided in previous posts on client validation in windows to work, but really do not like the solution.   Having to paste in all of the form content into the Content() method is not a good solution and with large pages is going to make for some very messy code.  For example:

 

    <% Html.Telerik().Window() 
           .Name("Window") 
           .Modal(true) 
           .Content(() => 
            
                %> 
                    <% using (Html.BeginForm()) {%> 
                        <%: Html.ValidationSummary(true) %> 
            
                        <fieldset
... form content here....

It would be much cleaner to use a solution like this where we can keep the form inside another page:

<% Html.Telerik().Window() 
       .Name("Window") 
       .Modal(true) 
       .LoadContentFrom("/Home/Popup/")  
       .Visible(true) 
       .Render(); 
 %>
..or even a partial view:
<% Html.Telerik().Window() 
       .Name("Window") 
       .Modal(true) 
       .Content("<div>... render partial view here....</div>") 
       .Visible(true) 
       .Render(); 
 %>

When I try the last two methods, the windows load great, but the client validation doesn't run.  If I go to /Home/Popup/ directly (outside of the windows load) the client validation works.   But, the minute I launch it inside the window using one of these methods, the client validation doesn't fire.   The validation client logic is injected properly into the page, but it just doesn't ever fire.

I have attached an updated version of the clientvalidation project that was posted here late last year.  /Home/SinglePage/ demonstrates how the client validation does work when the entire form is in the content method.  /Home/Index/ demonstrates how the client validation doesnt work when the form is loaded into the window.

FYI - the reason we are trying to do this is that we have a very large app with over 60 entities (code tables) that users can customize for their company.  We are setting this up with a tree view in the left pane of a splitter, with the grid attached to each entity displayed in the right pane.  We would like to put a CREATE NEW button on the grid and have it open into a new window in case a user wants to add a new row.  This was easy to do in ASP.Net with the RadWindow, but has been a real pain with MVC. 

1 Answer, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 02 Feb 2012, 08:49 PM
We were able to finally get this to work by putting the scripts inside the partial views also.  We have them in the layout pages, and they are showing up in the final rendered page (with the window in it), but they only fire when they are also added to the partial views:

 

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
Tags
Window
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Share this question
or