Example of c # TextBox. MaxLength in asp.net,

Source: Internet
Author: User

Example of c # TextBox. MaxLength in asp.net,

TextBox. MaxLength attributes
Obtains or sets the maximum number of characters allowed in a text box.
The maximum number of characters allowed in the text box. The default value is 0, indicating that this attribute is not set.
Use the MaxLength attribute to limit the number of characters that can be entered in the TextBox Control.

Note: This attribute applies only when the TextMode attribute is set to TextBoxMode. SingleLine or TextBoxMode. Password.

The MaxLength of TextBox is invalid.


Method 1: Verify the control (practical)
Verify controls

The Code is as follows:
<Asp: TextBox ID = "txtConclusion" MaxLength = "200" TextMode = "MultiLine" Height = "100px" Width = "400px" runat = "server"/>
<Asp: RegularExpressionValidator ID = "txtConclusionValidator1" ControlToValidate = "txtConclusion" Text = "more than 200 words" ValidationExpression = "^ [sS] {0,200} $" runat = "server"/>

Method 2: add some JS Code restricted by the client. Example:
Code

The Code is as follows:
<HTML>
<HEAD>
<Title> WebForm6 </title>
<Meta name = "GENERATOR" Content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "CODE_LANGUAGE" Content = "C #">
<Meta name = "vs_defaultClientScript" content = "JavaScript">
<Meta name = "vs_targetSchema" content = "http://schemas.microsoft.c (www.111cn.net) om/intelliisense/ie5">
<Script language = "javascript">
Function isOver (sText, len)
{
Var intlen = sText. value. length;
If (intlen> len)
{
Alert ("The content length must Less than or Equal" + len );
SText. focus ();
SText. select ();
}
}
</Script>
</HEAD>
<Body MS_POSITIONING = "GridLayout">
<Form id = "Form1" method = "post" runat = "server">
<Asp: TextBox id = "txtName" style = "Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: Running PX" runat = "server"
TextMode = "MultiLine" Height = "pixel PX" Width = "271px"> </asp: TextBox>
</Form>
</Body>
</HTML>
Public void Page_Load (object sender, System. EventArgs e)
{
This.txt Name. Attributes. Add ("onblur", "isOver (this, 1000 );");
}
From: http://www.111cn.net/net/160/66645.htm


How to automatically generate Abcd and 123 in aspnet

If you use numbers, you can use for directly. If you use letters, you can store a string in advance and use it as a char array... Or directly convert the number to char.

What is the relationship between C # In aspnet and C ++ in C?

ASP. NET seems to support C #, Visual Basic, and Jscrip in three languages.

C # (C sharp) is Microsoft's solution to this problem. C # is the latest and object-oriented programming language. Using a simple C # language structure, these components can be easily converted to XML network services so that they can be called over the Internet in any operating system in any language.
Most importantly, C # enables C ++ programmers to develop programs efficiently without losing the original powerful functions of C/C ++. Because of this inheritance relationship, C # has a great similarity with C/C ++. Developers familiar with similar languages can quickly switch to C #.
1. The modern design of C # can eliminate many common C ++ programming errors.
2. C # languages allow extended metadata defined by types. These metadata can be applied to any object. Project builders can define attributes unique to a domain and apply them to any language element-class, interface, and so on.
3. built-in build Object Model (COM) and based on Windows? API support;
4. Native Pointer is allowed ).
That's all. I recommend a post for you.
Bbs.gxut.edu.cn/...page00001

If you are not familiar with ASP. NET, an ASP. NET tutorial ASP. NET technology details and application examples (C #), but I have not downloaded an electronic tutorial. You can buy a book. It should be inexpensive and easy to find.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.