hi!
i wanted to set a maximum limit of characters of textbox in the properties but i can't find where it is located unlike in vb 6.0 you can set the characters in maxlength...thank you in advance..

Dani AI

Generated

A short diagnosis tied to the thread: , and correctly pointed out that TextBox controls expose a MaxLength-like mechanism, but the symptom described by — MaxLength set to 15 while the control effectively stops at ~10 and an Overflow occurs — usually traces to one of two root causes: an ASP.NET WebForms TextBox rendered as a multiline TEXTAREA (where MaxLength is not enforced in older frameworks), or server-side numeric conversion of the TextBox value into a 32-bit Integer (Int32) which overflows once the input exceeds Int32 limits. (learn.microsoft.com)

Web (ASP.NET) checklist and a quick server-side workaround:

  • Confirm the control type in the .aspx markup (TextMode attribute). Historically a Multiline TextBox renders a <textarea> so MaxLength will not be emitted to the browser. (learn.microsoft.com)
  • To force client-side limiting without heavy JS, add the HTML maxlength attribute from code-behind (or use client-side trimming/validators). Example VB in Page_Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        TextBox1.Attributes.Add("maxlength", "15")
    End If
End Sub

The Attributes collection is the supported way to add raw HTML attributes; newer .NET releases (4.7.2+) also improved maxlength behavior for multiline TextBoxes. (learn.microsoft.com)

WinForms / overflow checklist:

  • Search the project for conversions like CInt / Convert.ToInt32 / Integer.Parse that run on TextChanged, Validating, button click handlers, etc. Int32.MaxValue is 2,147,483,647 (roughly 10 digits), so parsing longer numeric strings will throw OverflowException. (learn.microsoft.com)
  • Prefer TryParse and larger numeric types when larger values are valid. Example VB:
Dim id As Long
If Long.TryParse(TextBox1.Text, id) Then
    ' accept id
Else
    ' handle invalid or too-large input
End If

Use server-side validation as the final guard (client-side limits can be bypassed). For WinForms MaxLength behavior and defaults see the TextBoxBase.MaxLength documentation. (learn.microsoft.com)

Recommended Answers

All 6 Replies

In vb.net also for textbox there is a property called MAXLength u can set the length there..

Or you can set it with code at form load:

TextBox1.MaxLength = 3

i already set the maxlength to 15 and also codes it to form load but the maxlength of the textbox is only 10 that if i exceed to that number i encountered an overflow..

by the way thanks for the reply:)

Are you have tried to set from textbox properties? On MaxLength.

Click the Textbox go to --> Properties --> MaxLength --> Desired Length(5,10)

Or you can set it programmatically YourtextboxName.maxlength=10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.