Hello there, sometimes we need to restrict the character length in Multiline Textbox and we know we can achieve by our logic in code-behind. Why don’t we try JavaScript? So I found something and modify it according to my need. Following the code which will restrict the limit of characters in TextBox.
Create web form [Default2.aspx] and copy paste the source code in it
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
<script language=”JavaScript” type=”text/javascript”>
//**** for master page the control name will be changed so you can access those name under source code.
//**** it could be –> ctl00$ContentPlaceHolder1$txt_commnets so u have to change it where u will use the textbox.
//**** and form name could be –> aspnetForm instead of Form1
var max=50; // 50 = max characters // we can set according to our need.



Recent Comments