views:

155

answers:

1

Im trying to use the example from this site to do client site validation. Im trying to use the html form tag instead of the "Html.BeginForm()" but doing that disables the client side validation. Does EnableClientValidation only work with Html.BeginForm. What is the difference?

<%@ Page Language="C#" Inherits="ViewPage<ProductViewModel>" %>

<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) { %>

  <%= Html.TextBoxFor(m => m.Title) %>
    <%= Html.ValidationMessageFor(m => m.Title) %>
  <%= Html.TextBoxFor(m => m.Price) %>
    <%= Html.ValidationMessageFor(m => m.Price) %>

    <input type="submit" />
<% } %>
+1  A: 

From the post you linked (Emphasis added):

The next step is to enable client validation for the form by calling EnableClientValidation before we call BeginForm. Under the hood, this sets a flag in the new FormContext which lets the BeginForm method know that client validation is enabled. That way, if you set an id for the form, we’ll know which ID to use when hooking up client validation. If you don’t, the form will render one for you.

The BeginForm method is obviously doing more in ASP.NET MVC 2 than just "rendering out a form tag" - it's also rendering out all the client script for the validation if that flag is set.

Zhaph - Ben Duguid
thanks for you response. Im trying to use telerik controls inside the Html.BeginForm and I get the RADScriptManager requires a form runat="server" error.If i add a html form tag e.g <form id="frm" runat="server"> on the page and add scriptmanager then the Html.EnableClientValidation is not triggered. Is there a way to get the use telerik controls inside the BeginForm method without using the scriptmanager?
ace
Ah. The joys of trying to mix webcontrols into ASP.NET MVC ;) I'm not sure - the control will want to use it's ScriptManager to ensure all its JS files are loaded. Which controls are you using? Have you considered other, more MVC friendly controls, such as CKEditor (http://ckeditor.com/).
Zhaph - Ben Duguid
yes, the "joys" :) Im using radcombobox, datepicker and radspell.
ace
Hmm, the Telerik site claims that the ASP.NET AJAX controls should work with MVC: http://www.telerik.com/products/aspnet-ajax.aspx, but I guess that's the current version, rather than 2.0 - have you tried asking them?
Zhaph - Ben Duguid
yes, no reply from telerik so far. Ive downloaded the RC1 today but it doesnt seem any different to the Preview version for Enableclientvalidation. Also they have removed the jquery validation and added the micrsofotmvc validation instead. just to complicate things even more.
ace