Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:14:40+00:00 2026-06-06T18:14:40+00:00

<asp:TextBox CssClass=txt ID=TextBox1 runat=server onkeyup=CountChars(this); Rows=20 Columns=35 TextMode=MultiLine Wrap=true> </asp:TextBox> I need to implement

  • 0
<asp:TextBox CssClass="txt" ID="TextBox1" runat="server"
             onkeyup="CountChars(this);" Rows="20" Columns="35" 
             TextMode="MultiLine" Wrap="true">
</asp:TextBox>

I need to implement word-wrapping in a multi-line textbox. I cannot allow users to write more then 35 chars a line. I am using the following code, which breaks at precisely the specified character on every line, cutting words in half. Can we fix this so that if there’s not enough space left for a word on the current line, we move the whole word to the next line?

function CountChars(ID) {
    var IntermediateText = '';
    var FinalText = '';
    var SubText = '';
    var text = document.getElementById(ID.id).value;
    var lines = text.split("\n");
    for (var i = 0; i < lines.length; i++) {
        IntermediateText = lines[i];
        if (IntermediateText.length <= 50) {
            if (lines.length - 1 == i)
                FinalText += IntermediateText;
            else
                FinalText += IntermediateText + "\n";
        }
        else {
            while (IntermediateText.length > 50) {
                SubText = IntermediateText.substring(0, 50);
                FinalText += SubText + "\n";
                IntermediateText = IntermediateText.replace(SubText, '');
            }
            if (IntermediateText != '') {
                if (lines.length - 1 == i)
                    FinalText += IntermediateText;
                else
                    FinalText += IntermediateText + "\n";
            }
        }
    }
    document.getElementById(ID.id).value = FinalText;
    $('#' + ID.id).scrollTop($('#' + ID.id)[0].scrollHeight);
}

Edit – 1

I have to show total max 35 characters in line without specific word break and need to keep margin of two characters from the right. Again, the restriction should be for 35 characters but need space for total 37 (Just for the Visibility issue.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:14:41+00:00Added an answer on June 6, 2026 at 6:14 pm
    <script type="text/javascript">
        function CountChars(ID) {
            var IntermediateText = '';
            var FinalText = '';
            var SubText = '';
            var Splitted;
            var Concatenated;
            var text = document.getElementById(ID.id).value;
            var lines = text.split("\n");
            for (var i = 0; i < lines.length; i++) {
                IntermediateText = lines[i];
                if (IntermediateText.length <= 50) {
                    if (lines.length - 1 == i)
                        FinalText += IntermediateText;
                    else
                        FinalText += IntermediateText + "\n";
                }
                else {
                    Splitted = IntermediateText.split(' ');
                    for (var index = 0; index < Splitted.length; index++) {
                        Concatenated = Splitted[index].length;
                        if (Concatenated + SubText.length <= 50) {
                            if (index + 1 != Splitted.length) {
                                SubText += Splitted[index] + " ";
                            }
                            else {
                                SubText += Splitted[index];
                            }
                        }
                        else {
                            FinalText += SubText + "\n";
                            SubText = "";
                            if (index + 1 != Splitted.length) {
                                SubText = Splitted[index] + " ";
                            }
                            else {
                                SubText = Splitted[index];
                            }
                        }
                    }
                    if (SubText != '') {
                        FinalText += SubText;
                    }
                }
            }
            document.getElementById(ID.id).value = FinalText;
            $('#' + ID.id).scrollTop($('#' + ID.id)[0].scrollHeight);
        }
    
    </script>
    
    
    <asp:TextBox ID="txt" onkeyup="CountChars(this);" Width="60%" runat="server" Rows="20"
                        Columns="50" TextMode="MultiLine" MaxLength="1000"></asp:TextBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multiline textbox : <asp:TextBox ID=txtBody runat=server TextMode=MultiLine Rows=10 Width=95% /> In
I have the following html: <div id=myDiv1_ class=formElement1><asp:TextBox ID=TextBox1 CssClass=formInput1 runat=server></asp:TextBox></div><br /> <div id=myDiv2_
i have a TextBox control on my masterpage <asp:TextBox ID=txtSubject runat=server Width=280px CssClass=formtxt onblur=if(this.value=='')
<asp:TextBox ID=txt_Subject runat=server CssClass=txt_box></asp:TextBox> <asp:RequiredFieldValidator ID=valSubjectRequired ControlToValidate=txt_Subject ErrorMessage=Subject is a required field. EnableClientScript=true Display=None
I have a multi line text box like : <asp:TextBox CssClass=txtform ID=txtWhom runat=server Height=78px
I have an asp:TextBox that looks like the following <asp:TextBox runat=server AutoPostBack=True ID=txtG1 ontextchanged=txtG1_TextChanged
I have a asp:UpdatePanel with a asp:Button and a asp:TextBox : <asp:UpdatePanel ID=UpdatePanel1 runat=server>
<asp:TextBox id=txtDate runat=server Width=70 Text='<%# DataBinder.Eval(Container.DataItem, Date) %>'/> <atk:MaskedEditExtender ID=meeDate CultureName=en-GB runat=server Mask=99/99/9999 MaskType=Date
My code: <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <asp:GridView runat=server ID=MyGridView AutoGenerateColumns=false> <Columns> <asp:BoundField DataField=Col1 HeaderText=Column
If I have a label and a textbox and a label <asp:Label ID=Label1 runat=server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.