Showing posts with label multiline. Show all posts
Showing posts with label multiline. Show all posts

Saturday, March 31, 2012

Text Box to a Database to a Label

Hi

Im fairly new to ASP.NET, im using 2.0.

I am trying to develop a page where the user can enter text into a multiline textbox and then when they click enter the text is stored in a Table in an SQLServer DB.

When the page is reloaded the text that was stored is outputed to a Label.

This works ok except for one small problem when I entertext in the text box which is more than one line IE

"Hello
my
name
is
Graham"

It is displayed in the Label as "Hello my name is Graham"

Does anyone know how to keep the text in the form that it was entered in the textboxwhen it is displayed in the Label?

Other wise I will not be able to have paragraghs etc, just one long string.

Thanks Graham

The text entered in the multiline textbox has crlf (Carriage Return Line Feed) for line breaks. When you display in html, you must replace those with <br /> to achieve the similar layout.

Hope it helps,

Joe

Monday, March 26, 2012

Text in asp:TextBox

I'm having some trouble with my Asp:TextBox (a multiline actually). I want to write some text in it, so I use the expression "NameOfTextBox.Text='Some text'". Unfortunatly 'Some text' is converted to HTML (for example: < is automaticly converted to &lt;).

I want to take care of any html-conversion myself. Is there a way to tell the textbox, that I want it to contain the the text without modifications?I'm not understanding where the conversion is taking place. I have a simple page below that loads a string into textbox and shows it as I've set it. Of course, it's impossible to actuallyshow that in this forum (grrr), but basically I'm setting the text to "< b >Hello< /b >" (no spaces in the tags. It shows the < and > characters in the text box. Is that what you mean?

<%@. Page Language="VB" %>
<script runat="server">
Sub Page_Load()
textbox1.text = "Hello "
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

I will make myself a bit clearer. If I use the code-line:

textbox1.text = "<"

I want the HTML generated to be something like this:

<textbox id=textbox1><</textbox>

As it is now, the result will be:

<textbox id=textbox1><</textbox>

The text is in some way automatically encoded to be displayed as proper HTML. I have problem, 'cause I use Swedish characters as ö and that is automatically encoded to &ouml;. See my problem?
The encoding of < into < in a textbox is normal and conforms to the HTML standard AFAIK.
The TextBox control automatically encodes the text. To get the proper ö, just set the text to a normal string with the special character to avoid double encoding:
simply writing textbox1.Text = "ö" will produce the desired character.

Does this help?
It works with writing just textbox1.Text = "ö", but the problem is that the text to be displayed is already encoded. The text is taken from a file, which has all its text in HTML-format. If there is no way to tell the textbox to display the proper text, is there a way to decode the html into text again (make ö into ö and so on)? If not, I think there are some other (complicated) ways to solve it.
You can try HttpUtility.HtmlDecode.
HttpUtility.HtmlDecode may be what I'm looking for. Thanks.

Text in Multiline

i have 3 to 4 text box

TextBox1.Text=abc;

TextBox2.Text=def;

TextBox3.Text=ghi;

TextBox4.Text=jkl;

SubmitButton

i also have,

TextBox5

what i want when someone clicks on submit button, the text in all the textboxes should be lined up in text box 5 one below the other like this

abc

def

ghi

jkl

but all i get is

abcdefghijkl

what is going wrong

my code is

TextBox5.Text=TextBox1.Text+TextBox2.Text+TextBox3.Text+TextBox4.Text;

Use System.Environment.NewLine in between each TextBox

string result = TextBox1.Text + System.Environment.NewLine + TextBox2.Text + .....

Thanks


it doesnt seem to work still i get the text in one single line

Did you set the last TextBox text mode to Multiline? I have tested and its working fine.

Thanks


Thanks for you suggestion once aagain..it works fine now

Saturday, March 24, 2012

Text manipulation

Hi

Can someone please help me!? I'm trying to work out how to take text from a multiline asp:TextBox and find and replace the \r\n characters with equivalent HTML <p></p> tags. So that when it is retrieved from the database it can be displayed as correct HTML!

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

Please can someone point me in the right direction!

Many thanks

Ross

Hey Dude!

Did you try this:

string.Replace("\r\n","<br/>") ?


kcis8rm:

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

You would be better off using one of the free rich text editors. Otherwise \r\r should find a paragraph break, then you would have to manipulate the result of your Replace() operation to add <p> to the beginning, and remove <p> at the end.




Dude

Check this out, I just figured that link for you: http://www.phptr.com/articles/article.asp?p=29585&rl=1

may be it gonna help you to solve your problem, try it out and let me know if it works, else paste your code and we will work on it together.


Hi

Thanks for the help, I think I've now sorted it :-)


I've now sorted this, however you brought up and interesting point! Can you point me in the direction of some of these free rich text editors please?!

kcis8rm:

Hi

Thanks for the help, I think I've now sorted it :-)

Good. What did you do? It might be of interest to others who find this thread.


I solved it by using a regular expression to replace the pattern \r\n\r\n (which shows a paragraph) with the text </p><p> and then adding a <p> to the beginning of the string and a </p> to the end of the string!


Excellent. Any chance of marking my post as the answer then?Wink

Tuesday, March 13, 2012

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000
but am able to type in an unlimited number of characters. Is there a way to
limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid
"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?
only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox "Enters" in text

Hello,

I have a MultiLine TextBox which text should be send to a SQL 2005 Database Table. How can I preserve "enters" (for breaks and new paragraphs) so that when the text is shown from the database it has paragraphs?

Thanks in advance.


the linebreak from a multiline textbox is actually a CRLF (environment.newline).

when you render data that came from a multiline textbox and you want to show the carriage returns on the screen, you need to replace them with a break tag "<br />"

i.e.

myText = myText.Replace(Environment.NewLine, "<br />")


For reference, you might also want to check this thread on exactly the same subject from earlier today:

http://forums.asp.net/t/1153952.aspx