Aspx page:
<asp:Label ID="lblMessage" runat="server" ForeColor="Red" EnableViewState="false" />
<p>
<asp:TextBox ID="txtDetails" runat="server" TextMode="MultiLine" Columns="50" Rows="5" /></p>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="SubmitData" />
cs file:
protected void SubmitData(object sender, EventArgs e)
{
var maxLength = 50;
if (txtDetails.Text.Trim().Length > maxLength)
{
lblMessage.Text = string.Format("Sorry, only {0} characters are allowed.",
maxLength);
return;
}
}
hope this help you