Raed
Raed

Reputation: 23

How to get HTML <textarea> value using c#?

How can I get the value of a textarea using c# ?

my issue is when I using MultiLine TextBox I can't get the full value !! I mean what I wrote including the
breake lines. ex:

  1. Google
  2. Micrisoft
  3. Yahoo

after saving above data it come's in one line 1.Google 2.Microsoft 3.Yahoo

Upvotes: 2

Views: 4216

Answers (3)

rgomila
rgomila

Reputation: 11

I made this in Visual Basic (easy translation to C#):

Dim convertedtext As String = TextBox1.Text.Replace(Environment.NewLine, "<br />")

and then, I saved convertedtext to the database. TextBox1 is the multiline textbox.

If you enconde the data to show it again (in a literal or similar) do the following:

HttpUtility.HtmlEncode(convertedtext).Replace(HttpUtility.HtmlEncode("<br />"), "<br />")

Upvotes: 1

Khadaji
Khadaji

Reputation: 2167

I'm not 100% sure that I understand the question - but maybe you want to look at the MeasureString method of the graphics class.

Upvotes: 0

Kieren Johnstone
Kieren Johnstone

Reputation: 42003

the very first result on Google showed me this:

http://www.daniweb.com/forums/thread26856.html

1- I right clicked the TEXTAREA and made it RUN as a Server Control....Its working fine..

2- You can also set the "multiline" property of the standard TextBox control. That control will either render an element or a element, depending on the properties you set. // TextBox1.TextMode = TextBoxMode.MultiLine

Simply create a TextBox, set TextMode to MultiLine, then you can get the text using the .Text property on your TextBox object.

It's always worth trying to find the solution for yourself first, then try it out, make mistakes and ask questions. It's the best way to learn.

Upvotes: 1

Related Questions