Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>MVC</strong></p> <p>See for a good example...</p> <p><a href="https://stackoverflow.com/questions/2818219/asp-net-mvc-html-validationsummarytrue-does-not-display-model-errors">ASP.NET MVC Html.ValidationSummary(true) does not display model errors</a></p> <p>Basically, you need to propagate the error <em>message</em> and also that fact that there <em>is</em> an error to your view from your controller. <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.modelstatedictionary.addmodelerror.aspx" rel="nofollow noreferrer">ModelStateDictionary.AddModelError()</a> will take care of both of these tasks for you.</p> <p>You can then use <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.html.validationextensions.validationsummary.aspx" rel="nofollow noreferrer">ValidationExtensions.ValidationSummary()</a> to display.</p> <p><strong>Webforms</strong></p> <p>You don't <em>have</em> to use a validator for this. Most people don't. A simple styled DIV should work well.</p> <p>eg.</p> <pre><code>&lt;div id="errorMessageDiv" runat="server"&gt;&lt;/div&gt; </code></pre> <p>Notice the <code>runat</code> parameter.</p> <p>Now in your code-behind you can try</p> <pre><code>errorMessageDiv.innerHTML = "some error message"; </code></pre> <p>If you really want to use a validator checkout...</p> <p><a href="http://weblogs.asp.net/ashicmahtab/archive/2008/12/12/putting-messages-into-a-validationsummary-control-from-code.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/ashicmahtab/archive/2008/12/12/putting-messages-into-a-validationsummary-control-from-code.aspx</a></p> <p>Basically you set the <em>ErrorMessage</em> and <em>isValid</em> parameters to the related validator in the code behind. The related <em>ValidationSummary</em> should display the error message.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload