I need a multiline textbox that preserves word wrap on post back


I need a control that can satisfy the following:

1. Must have word wrap (like a multiline textbox or textarea). Word wrap should support pasted text as well as entered text.

2. Must be able to specify maximum line length (35 characters) and maximum number of lines (4).

3. When posted back, I need access to each line of text as it looked on the clients page, so it can be stored in 4 different database fields that each have a maximum length of 35 characters.

This is all in order to spare users the hassle of entering their four permitted lines of text in 4 separate text boxes.

Do you have tips for getting this kind of functionality? I am hoping I can avoid making this control from scratch. I have been looking at commercial products but they seem to center on HTML editing functionality. Also, I am not convinced that I will get 2. and 3.

Thank you. 

1/10/2007 1:11:51 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 48

Hi, i think this can be achieved with the help of javascript. Like this:

<asp:TextBox ID="TextBox1" runat="server" Height="124px" TextMode="MultiLine" Width="267px" onkeydown="isValidInput(event);"></asp:TextBox>
function isValidInput(e)
var obj = document.getElementById("TextBox1");
var v = obj.value;
var array = v.split("\n");
if(e.keyCode == 13 && array.length > 3)
return false;
More info about it can be found here:

Hope it helps.

1/11/2007 5:21:48 AM

No. A multiline textbox or textarea does not insert new line characters when it performs word wrap.

This javascript function can only be used to limit the number of line breaks the user inserts manually. So it does not satisfy 3.

Thanks anyway.

1/11/2007 8:26:42 AM

    What exactly is wrong with using 4 separate textboxes?  If the text really needs to be divided up this way, it would seem to make sense.

   Otherwise, why not just use an onkeydown event handler to check each line?  You could do a split on the newline character, parse each array item (i.e. line) to see if it was longer than 35, and if so, add a carriage return.  If the total number of lines exceeds 4, you'd have to decide how you want to handle that for the user.
   This way when you post back, the lines are still correct because you've added the formatting to the textbox contents, and if the user needs to pull it up again, you just put each line into the box with CRs between them.

    Of course that seems like a lot of trouble just to avoid using 4 textboxes (and if the user turns Javascript off or has accessibility requirements, you could be hosed).

Peter Brunone
Founder, EasyListBox.com
Do the impossible, and go home early.
1/11/2007 4:52:53 PM

What is wrong abour 4 textboxes is that some users have been used to typing mindlessly and now thay have to think about where to divide their text and change focus manually. 

It doesn't matter that the control is scripted. I just feel that there must have been done something like this before to save me from coding everything from scratch.

I thought about doing it the way you propose... but I would lose the word wrap functionality or have to implement it myself - none of that is acceptable right now.



1/15/2007 8:34:36 AM

In the end I found out how to do it, and without javascript even.

The control I needed was the normal html textarea control. 

The trick is that the html TextArea has an attribute value wrap='hard', which is not mirrored in the ASP.NET multiline textfield. Setting this attribute will cause ordinary line breaks ('\r\n') to be inserted wherever word wrap has occurred. when the page is posted back. Then I can split the textarea content into lines on the server.


textarea id="taMessage" Mandatory="false" wrap="hard" cols="36" rows="4" runat="server" style="font-family:Lucida Console, Monospace; font-size: 13px; overflow-y:hidden"></textarea>

I use a monospace font and the cols attribute to set the maximum line length - cols for some reason needs to be set 1 higher than the number of characters I want to allow.

The main drawback is that there is no way to stop the user from entering more than 4 lines. The content wil scroll to accommodate the extra lines. Javascript cannot be used to count the number of lines  because it is impossible to detect the soft line breaks that result from word wrap. So there is no way around validating the number of lines on the server and clipping the content and/or warning the user.

1/19/2007 11:25:12 AM

   Well, duh; I should kick myself for not thinking to mention wrap="hard".

   Thanks for keeping us updated; be sure to write back if you find a way around it (maybe you could post to a page that doesn't return any data and then get a quick line check via AJAX?)


Peter Brunone
Founder, EasyListBox.com
Do the impossible, and go home early.
1/21/2007 3:39:12 AM

Similar Artilces:

Do I need to validate against malicious POST backs using .net form components?
Ok, I'm moving from classic asp to .net 3.5 (I know big jump)In classic ASP you always needed to verify POSTs weren't malicious, however I'm wondering how much checking I need to do with .net.ie. I have a textbox called textbox1.  I've set textbox1.maxlength=20.  I then want to insert textbox1.text into a DB column varchar(20), I feel as if I do not need to verify the length as was needed in classic ASP, because I'm guessing textbox.text won't return a value longer then textbox1.maxlength would allow.One step further, take dropdownlist1, bind it to a datasou...

Could PB .NET Web Form POST security Information to others web page??
This is a multi-part message in MIME format. ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable Hi,=20 Have anyone came across the requesion to POST security informations from = PB .NET web form web page to other web site?? I have tried many datys, Could any kind man give me some suggessions?? thanks & Best regards Leon ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/html; charset="big5" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML P...

hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

How to preserve values in a web form when navigating to a different page and then going back to the original page using the back button ?
   I am working on a C#/ASP.NET web application. The web application basically consist of 3 web forms. Each form contains several controls such as an edit box, and some drop down list box controls. Basically I need to find out how to preserve the values in a web form when a person navigates to a different page. For example, suppose that in my web application I navigate from my first page (First.aspx) to my second page (Second.aspx). Now if I press the browsers back button, I want the application to retain the values for the controls that were in my first web form "first....

Web form debugging
Hi, This is SOS call, since I have no idea what happend, but my web page is not working any more though I didn't change a thing. I have a web page, containing datagrid, dataset, and listbox. The user chooses an item from the listbox, push the button, and get the relevant records in the datagrid.  I added another feature: "quick search" containing textbox and another button, and when the user type something in the textbox and push the button, the datagrid being populated from the new search algorithm instead of the listbox. Every thing was working perfect, till I changed something, a...

Prevent browser refreshes from posting back an already-posted-back form?
HiI have a formview in insert mode for inserting items into a gridview.  Each item is some description text, a price, and a quantity.  I'm using SqlDataSource controls while I learn about the New Way of Doing Things.If I insert an item, and then refresh the now-posted-back page in my browser, the same item gets inserted again.  I would like to prevent this, ideally without response.redirecting on FormView.ItemInserted every time a new item is inserted.  I don't think it'd be a question of clearing the inputs and validating for data, would it?  I mean, an F5 will repo...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Need Windows Form to Retrieve Information From Web Form
I have a cash and carry web site that customers can order products, the next day come in to the company to pay and pickup. I would like to create a windows application for the company to do two things: 1. download all the orders from the day before 2. upload price changes, product changes, category changes I've search the internet and forums and the only thing I can find that I think would actually link these two together would be a web service. Can you please tell me if I am heading in the right direction or if there is another method to link the two applications, if there are any pitf...

problems with web control textbox posting back
hi,  i have a simple form with a couple of vb/asp.net web server side textbox controls. They are set to not auto postback  when the text changes ( but they do seem to auto postback when a return key is entered which is fine for me ).   If i hit the return key when focused in these text boxes they cause a postback event but I cannot capture it  server side. I get redirected back to my default web page . If i use an ordinary HTML input box - the same thing  happens.  If I use an ordinary submit html button control everything works fine.  My question...

http handlers and web form post backs
Wondered if anyone could point me in the right direction for my problem? I have a http handler that captures .html requests and transfers them all to a default.aspx which then dynamically loads in all the web and user controls required for that web form. My problem is if I request, for example, contact.html it will load my contact form correctly but when I submit my contact form the action points to default.aspx. So when I submit it the user sees default.aspx in the address bar instead of the intended contact.html. I either need to change my http handler, modify the action of my ser...

Web Form Scroll Position After Post Back
Hello, Can someone tell me how to save the webform position so that after a post back the user does not have to scroll down to the position they were at when they pressed the submit button?  The target is IE6.   Much Appreciated, Paul. The Page element in VS2005 has a MaintainScrollPositionOnPostback property for this.  Otherwise you will have to write some Javascript to get the current scroll position, save it (say) to a hidden field on the page with a runat=server attribute, then on Javascript onload, scroll to the new position.  Do a Google on "Javascript" and "S...

Need to post url query string from web form.
Hi, I've got a security camera hooked to the local area network here via a video server (which responds to url querystring commands via cgi). I need to be able to post querystrings from a webform, without the page actually leaving the page. Any ideas on how to post url data without leaving the page? I was thinking of a hidden iframe, but I don't know how to dynamically post urls to it, of course there's probably a better way anyhow. in your pages codebehind, you can call another page using System.Net.HttpWebRequest. That would allow you to call another url with querystring param...

AJAX modalpopup to post data back to web form
I have a form with a button on it.  When the button is clicked, an ajax modalpopup is displayed  and the user can then input some data into a text field and click another button that will query a database and return with a gridview of information pulled from the database.  In the code behind I have the gridview_selectedIndexChanging set up to catch the index of the selected row and then pull the data from the cells into hidden text fields all within the popup.  The OK button is tied to some code behind that should transfer the values in the hidden text fields to...

web form doesn't post back.
From a form in windows (non-asp), I need to send form variables to an asp.net web form and have it post back. Whenver I perform a web request through my windows forms code the web form doesn't seem to post back (it should have edited a file on the server). What am I doing wrong? Is there anything I can do to make the web form accept this kind of request from windows? From your question, what i understood was when the browser window opens, you want some predefined action to be performed, based on the variables you sent. If its the case, you can pass the variables as querystring parameters a...

Web resources about - I need a multiline textbox that preserves word wrap on post back - asp.net.web-forms

NestaDB for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about NestaDB on the App Store. Download NestaDB and enjoy it on your iPhone, ...

Open Directory - Business: Telecommunications: Equipment: Business Systems
... companies that primarily repair & refurbish telecommunications equipment for other companies or individuals. This equipment includes multiline ...

Wikipedia:AutoWikiBrowser/User manual - Wikipedia, the free encyclopedia
/u int - /u loads a specified (either by user name or by its number in the list of profiles) user profile, and logs into it. Profile must exist, ...

Windows 7 - Wikipedia, the free encyclopedia
less than three years after the release of its predecessor, Windows Vista . Windows 7's server counterpart, Windows Server 2008 R2 , was released ...

NEC PBX & Telephone Systems For Small Business Sydney
The NEC Xen Axis/Master telephone system has been discontinued. We continue to provide spare parts and support for this system through our offices ...

Surperformance© ratings
Live market prices from All Stock Exchange. Stock market advice and financial information for active investors. Real-time recommendation leader. ...

ACE Group - A Leading Global Insurance Organization
... is one of the world's leading global commercial property and casualty insurance organizations The ACE Group is one of the world’s largest multiline ...

Upcoming Adobe Reader Update for iOS and Android
Engineering blog for Adobe Reader on mobile platforms

Aite Group Latest Research
... a Member BLOG Home > Press > Press Releases News from Aite Group, LLC Toggle Advanced Search Claims Management Systems for Top-Tier and Multiline ...

Price Drop: Goal ToDo
... categories support.• Calendar and List double Views, both with swap function • Customizable List swapping view• Quick Add Task Entry with multiline ...

Resources last updated: 12/6/2015 1:01:43 AM