Fix broken text wrapping and control input text length in TextBox control

Hi!

I'm developing a(nother; it's my second!) ASP.NET application that right now is giving me fits.

On one of my screens, the user needs to be able to enter large amounts of text into three database fields. The database fields are all char(350).

I'm having two problems with this. First of all, I found that when editing an existing record, text in the fields would wrap in a manner similar to this:

Wow, what a sorry
performance!

The text box is much wider than the text "Wow, what a sorry", so I couldn't figure out why the text was wrapping. I tried setting the Columns property to 90 (which is about how wide the text box actually is), but the text wrapped in the same manner.

This isn't acceptable. How can I fix this?

Second question: While researching potential solutions to the above problem in the documentation in Visual Studio (with no success, which is why I'm here), I also ran across the fact that the MaxLength property doesn't have any effect when the TextBox's Mode is set to MultiLine. That seems fairly stupid in itself, but my question is: Is there any smarter way to prevent the text from being longer than 350 characters than checking it in code?

Thanks,

Tim

 

0
TimK65
3/30/2007 4:52:45 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

8 Replies
1026 Views

Similar Articles

[PageSpeed] 14

Are you sure there aren't any type of line breaks or returns within the existing data that may be causing this? If so, you may need to clean your data prior to loading. Secondly, you could always use a CustomValidator with a little JavaScript routine to check the user's input or you could extend the TextBox control itself to work properly. Regardless, there are plenty of articles on how to do either.
Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
3/30/2007 7:17:31 PM

I found that when editing an existing record, text in the fields would wrap in a manner similar to this:

There are probably carriage-returns in the text (<BR> or \n).  You may need to filter them out.

The MaxLength property will stop a user from entering too much text.  If you jam text in programmatically, like from a database, it will have no effect. 

 


Steve Wellens

My blog
0
SGWellens
3/30/2007 7:21:16 PM

Hi Ed,

Thanks for replying.

There are no line breaks in the existing data. 

I don't know JavaScript and don't know how to extend the TextBox control, and am not really prepared to learn either under deadline pressure. :) I think it'll be easier to validate the text length in code, but I still need a solution for the wrapping.

Best,

Tim


0
TimK65
3/30/2007 7:23:30 PM
How about setting the TextBox.Width property instead of the Columns property. Does that do anything? It seems awfully odd.
Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
3/30/2007 7:30:03 PM

Hey Steve,

AFAICT there are no line breaks in the existing data.

The documentation (note something I forgot to mention: I'm using Visual Studio 2003) clearly states that the MaxLength property is ignored if the TextMode property is set to MultiLine. Preventing the user from entering too many characters is all I need to do, since the data in these fields will only ever come from users (the data I used in my example in my initial post is just sample data I stuck in the table to make sure I was able to fetch it and display it correctly...which I can, except for the stupid wrapping).

I just tested the TextBox control (with MaxLength set to 350 and TextMode set to MultiLine), and it happily let me gallop right on up to 400 characters without blinking. No 

Thanks,

Tim

0
TimK65
3/30/2007 7:34:15 PM

Hey Steve,

AFAICT there are no line breaks in the existing data.

The documentation (note something I forgot to mention: I'm using Visual Studio 2003) clearly states that the MaxLength property is ignored if the TextMode property is set to MultiLine. Preventing the user from entering too many characters is all I need to do, since the data in these fields will only ever come from users (the data I used in my example in my initial post is just sample data I stuck in the table to make sure I was able to fetch it and display it correctly...which I can, except for the stupid wrapping).

I just tested the TextBox control (with MaxLength set to 350 and TextMode set to MultiLine), and it happily let me gallop right on up to 400 characters without blinking. No 

Thanks,

Tim

0
TimK65
3/30/2007 7:47:39 PM

Hi again Ed, and thanks for your patience in replying. Smile

The Width property is set to 424px, which presumably corresponds to the width at which I drew the control on my window, and which is the width I want. That looks to correspond roughly to the actual width on my screen, too: my resolution is set at 1280 pixels wide, and the TextBox control looks to be taking up about a third of that width. The text is wrapping long, long before it reaches the right-hand side of the text box; that's the problem. (I guess I really didn't make that clear earlier, apologies for that.)

PS I've just coded my Visual Basic program to truncate the text to 350 characters before it gets included in my SQL INSERT or UPDATE statement, so the user doesn't get the "String or binary data would be truncated" error message on submit. I'm not crazy about that solution, but I can live with it. But I really do need to get the wrapping fixed.


 

0
TimK65
3/30/2007 7:53:56 PM
I've pretty much ran out of ideas. Strange problem...
Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
3/30/2007 7:56:54 PM
Reply:

Similar Artilces:

Which validation control to use to control input textbox text length ?
I have a formview to insert record and I want one field to limit to text char length of 50. Which validation control I should use and how to set it ? ThanksThanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped. Check this link.. http://www.codeproject.com/KB/aspnet/Textarea_Length_Validator.aspx Edit: If it is normal single line TextBox, you can set "MaxLength"..Check this code..   <asp:FormView runat="server" ID="formView1" > <...

MS Publisher / Word-like textframe web control... flowing text between text controls
Does anyone know of an ASP.Net web control capable of linking text boxes/frames together similarly to the Publisher & Word textframe objects (via the NextLinkedTextFrame property in Publisher or the TextFrame.Next property in Word)? The goal is to have text flow from one textbox into another. Thx.....

preserving the layout of text input via text input control
Ok what I want to do is, when using the text input control all cr, lf, crlf and spaces are preserved when the content is input in a db and that the information/layout is preserved when viewing it in a text input filed or grid control.any ideas   jim When you input text via a multiline textbox and insert it into a database your specified line breaks will be maintained. When retrieving the record, you will need to do a replace on the string in order to interpret these line breaks in your html:myField.Replace("\n", "<br />")Does this answer your q...

length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ?
hello friends length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ? second example is ..... textbox1.text is greenhouse.. i want to get green from textbox.text cheer Mark as me if my question or my answer can be helpful for you :) Hi,you can always perform a Trim to a retrieved string to delete the leading and trailing space characters. For your second example where you want to gt a part of the retrieved string you can use the SubString method of the String class.Grz, Kris. Read my blog. Handy Firefox plugins for web developers.Workar...

Changing the text of an input (text) control
Hi everyone, please answer the following: I have a html input control as follows  <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords %>" name="newSearch_keywords""/>    When the page loads I need to look at the text of this input field and remove any * chars that are in the text. Thanks for your help <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords.Re...

Web Control with <abc:Control>TEXT HERE</abc:Control>
I'm trying to create a custom web control and support putting stuff in the middle - between the openning and closing tags:  <abc:Control>TEXT HERE</abc:Control> I would like to be able to put both text and other web controls between the tags. How do I do this? hi, why not the normal web user control? It also works fine. Maybe it is hard to create a control with the openning and closing tags...

chinese character in rich text control and text control
I have a chinese character in either rich text control or text control. The character is look fine if it is a small size (10, 12), however when the font size is changed bigger (36 or 72), the character is out of shape(many dot, not smooth). Is anyone has any idea to print a bigger chinese character from pb7.03. ...

Text does not wrap correctly in rich text control
Hi, I'm having this problem: 'Text does not wrap correctly in rich text control'. I'm using PB10.5.1. I've done some research on the Web and tried: set the following variable in the pb.ini file: [RichText] PageSizeAsControlSize=1 Should I install PB10.5.2? Does it resolve the problem? Any help would be appreciated. Thank you. Joan A bit more description about the problem. I have a rich text control in my app. I have tried to set property to 'Wordwrap, which dosen't work. I have tried to set the following variable in the pb.ini file: ...

How to populate other text controls by losing focus of one text control
 Hi All,Iam new to ASP.net. Here is a small illustration about my prob. I have 3 text controls in a page i.e which represents zip,city,state. I want to populate city and state after entering zipcode into zip text control i.e something like focus lost event on zip text control. Any solution regarding this thanks and regards,vijaycanaan How about OnTextChange: http://msdn.microsoft.com/en-us/library/aa710190(VS.71).aspx EricPascarello.com | Twitter epascarello | LinkedIn Hi vijaycanaan We can capture the following event when TextBox  lost focus: On Server-Side:We...

control text in a text box inside a Form view
I want to get text from a querystring into a text box that is prt of a form view. I have tried writing code in the page load that changes the text value inside that text box but i get the error that the texbox name is not in the current context. My question is how to call a textbox (or any other control) inside a form view? You can use the FormView's OnDataBound event to access the textbox on your formview: OnDataBound="FormView1_OnDataBound" Protected Sub FormView1_OnDataBound(ByVal sender As Object, ByVal e As EventArgs)        If FormView1.Curren...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Setting the height of a Text Input Control on a User Defined Control
I have a user defined control. I am using absolute positioning. I am setting the height and width of a text input using an embedded style. It look fine in the user control window but when I insert the user control onto a page, the heigth of the text control is too large. I cannot seem to control the height on the page I place the user control onto. Any help?Virtually yoursWilliam Main Hi, I think it is better to create the user control to be created as  position = Static to get more layout control of the web user control when used in other pages. For more layout control on all ...

Text Formating in a .Net Server Textbox Control
I have a webform with a textbox that I use for inserting a phone number. I would like to mask the text box so that when the user inserts the phone number will look like this (123)555-5555 I need to send the phone number as a param to a web service that require that format. to be able to return a query result. I'm usin VS 2005 Does any of the VS .NET server controls have any type of masking capabilities.?   Tia Charles  Charles UrbinaSolucion Software Corp. None of the standard Web Server Controls offer this "masking" feature -- something akin to Windows TextBox control.&...

Enabling button after text changed on text box from form view control
I'm using form view to display some text box that contains user's personal info. There are "save" buttons for each text box which are disable as default. I want to enable them when text is changed on the the text box. I don't know how to write the the JavaScript function to do this task and i also don't know how to call the function from the the textbox control (onchange or ontextchange?). Here is the formview code: <asp:FormView ID="FormView1" runat="server" DataSourceID ="personalSQL"> <ItemTemplate > <ta...

Web resources about - Fix broken text wrapping and control input text length in TextBox control - asp.net.web-forms

Gift wrapping - Wikipedia, the free encyclopedia
Gift wrapping refers to the act of enclosing a gift in some sort of material. Wrapping paper is a kind of paper designed for gift wrapping. Gifts ...

Wrapping up F8 2015: Keynote and Session Videos Now Available
Wrapping up F8 2015: Keynote and Session Videos Now Available

Dog Is Dead - Christmas Wrapping (The Waitresses Cover) - YouTube
... special Christmas treat, the Dog Is Dead lads are giving you the gift of music this year with their cover of The Waitresses - 'Christmas Wrapping'. ...

Wrapping the NBN in cotton wool
NBN Co may have been given legislative protection that is unsurpassed in the nation's history, but is it the biggest anti-competitive arrangement ...

The science of app-wrapping - MDM, Networking, wireless, mobile, IT management, bring your own device ...
BYOD brings out the classic problem between control of corporate information and individual freedom. It kicks it up to a whole new level because ...

Why wrapping up really can keep the winter colds at bay
Doctors have long insisted we catch more colds in chilly weather because we crowd indoors in poorly ventilated rooms. But this study suggests ...

Surrey Six trial wrapping up with final arguments
The Crown in closing arguments at the trial of two men accused in the murder of six people shot dead in a Surrey highrise apartment seven years ...

Japanese store Takashimaya demonstrates 12-second gift-wrapping technique - Lifestyle from CTV News
In yet another sign that the Japanese have much to teach us about basic life skills, a viral video from a department store shows you how to wrap ...

Puppy Christmas: Cute Puppies Play With Wrapping Paper
Who wouldn't want a box of puppies for Christmas?

Sources: Adobe wrapping up CS6 development, public beta launching soon
Demo of improved content-aware editing in Adobe CS6 According to previously reliable sources, Adobe is finishing up development on one of their ...

Resources last updated: 12/10/2015 8:24:33 PM