---
title: "Show message when user exceed limit size of a textbox in asp.net mvc app"  
description: "Show message when user exceed limit size of a textbox in asp.net mvc app"  
author: "Manish Kumar"  
published: 2017-11-15  
updated: 2017-11-16  
canonical: https://www.mindstick.com/forum/34363/show-message-when-user-exceed-limit-size-of-a-textbox-in-asp-dot-net-mvc-app  
category: "c#"  
tags: ["mvc4"]  
reading_time: 2 minutes  

---

# Show message when user exceed limit size of a textbox in asp.net mvc app

Show [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) when [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) exceed [limit](https://www.mindstick.com/forum/159824/explain-the-purpose-of-the-limit-and-offset-clauses-and-how-are-they-used-for-pagination) size of a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in [asp.net mvc](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) app

I am developing a [mvc application](https://www.mindstick.com/forum/12932/how-to-consume-webservices-from-asp-dot-net-mvc-application) in that I want to display a message when the user types more than 20 [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) in the textbox. This needs to [validate](https://www.mindstick.com/forum/1490/what-is-better-solution-for-validate-form-textboxs-value) without clicking on any validate button.

This is my current code :

```
<span class="field">@Html.TextBoxFor(d => d.Name,new {maxlength=20})</span>
```

## Replies

### Reply by Sunil Singh

Use this code

In the Model

```
[StringLength(250, ErrorMessage = "Description must not be more than 250 chars")]
        public string Name{ get; set; }
```

##### View code

```
HtmlHelper.ClientValidationEnabled = true;
  HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

<div class="col-md-12">
                                <div class="form-group">

                                    @Html.TextAreaFor(m => m.Name, new { @class = "form-control"})
                                    @Html.ValidationMessageFor(x=>x.Name)
                                </div>
                            </div>
```


---

Original Source: https://www.mindstick.com/forum/34363/show-message-when-user-exceed-limit-size-of-a-textbox-in-asp-dot-net-mvc-app

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
