How to get HTML <textarea> value using c#? - 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:
Google
Micrisoft
Yahoo
after saving above data it come's in one line
1.Google 2.Microsoft 3.Yahoo

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.

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 />")

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

Related

Retrieve text from database and format it on the front end of the website

I have some text currently stored in my database table as nvarchar.
I am currently retrieving the text using a stored procedure and binding it to a literal within a gridview on the front end.
What I would like to do is to retrieve the text and then format it , like inserting line spaces and making
certain area bold. Is it possible to do so ? Can anyone give me an idea of how it can be done ?
One idea thats striking me is to use XML while storing the text . But even if I do that how would I make a certain part of the text bold and include line spaces.
So currently, my text is stored in the database table column nvarchar(max) as:
This is the heading this is the content
What I would like to do is to display the above within a gridview like:
**This is a Heading** (heading in bold)
This is the content
The simplest method (one I have used several times) is to store the html in the table like this:
<h1>This is the heading</h1>This is the content
You will have to add special handling for working with html, but it works just fine.
You can also store the header string in one field, and body in another.
Short of that, you would have to have some indicator telling the front which part of the string should be bolded, etc. and that can get very complex
Short answer is that this is possible but takes some work.
You first need to decide in what format are you going to store the data and how can you specify format on the client side, before text is entered into database.
If you have WYSIWYG editor for text – html conversion you can try storing the HTML. This will be the easiest way in terms of storage.
If you decide to use this method note that you’ll need to do a lot of validation on the server to avoid cross site scripting attacks. Shortly put – make sure the HTML you get on the server doesn’t contain any javascript or any tags apart from those you want to support.
Its better to use Editor of AJAX Toolkit, doesnt required any other thing, its a complete editor, you can even color your font as u wanted.

TextBox display returns from RichTextBox?

I am creating an invoice program for a small local company but have run into sort of a problem. I have it setup so the invoice is printable by taking a screen shot of the application then remove all image detail so it is just the text from the Windows Form.
Problem is RichTextBoxes do not support drawing the text from them using DrawToBitmap. To fix this issue I am attempting to use a normal textbox. When inputting the address into a new textbox it does not show the returns in the text so it is all bunched up. Is there a way to fix this?
First all, I'll assume your TextBox's Multiline property is set to true.
This will work:
textBox1.Text = string.Join(Environment.NewLine, richTextBox1.Lines);
This code formats the text in your RichTextBox (in its Lines property) so your TextBox will display it properly.

Wrapping text in C# dialog box

I've got a dialog box that pops up with a dynamic list of numbers, and I'd like to get the box to wrap the text because at the moment it displayed up to screen width and then cuts the rest off.
I know I can use \n to declare a new line, but the list is dynamic - it could be one item, it could be 20.
Is there any way to tell the dialog box to wrap text?
Edit: clarification + example code
I'm not using MessageBox.Show() - our code uses its own defined message box class, but the guts of it calls System.Windows.Forms.Form.ShowDialog(parent). Maybe this isn't as well-behaved (i.e., doesn't wrap) as MessageBox.Show()?
Create your own simple form and add a label. Do the wrapping there... You cannot do that much things with Dialog boxes.
In this way you have much more flexibility to show your information to the user.
Are you using the System.Windows.Forms.TextBox? It has a property WordWrap that you can set to true
No other way for a standart MessageBox. Only creating your own form.
You could programmatically format the text by restricting each line to a specific number of words then inserting a \n or Envoronment.NewLine

List of Strings to Links

i was wondering if it is possible in c# to set to a text box a list of strings that are clickable links? at the moment i can set the text box like this
txtBox.Lines = values.ToArray();
ideally though i would like them as links if possible? maybe link labels or something?
(I'm assuming you're using Windows Forms; the answer for WPF/Silverlight may be slightly different.)
A textbox just contains text - it's not "rich" enough to have links.
If you want a list you might want to consider using a ListBox of some description - or possibly a RichTextBox; I haven't tried creating links in a RichTextBox, so I don't know whether it's possible.
Of course, you haven't specified what you want to happen when the user clicks on the links, either...
Use RichTextBox and check this - http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx
You can try using Windows.Forms.Controls.LinkLabel. It allows storing multiple links along with the text in it.

AutoEllipsis at the beginning of a label

I have a label on my form which is used to display a path. Occasionally the path is too long to display, so I turned on AutoEllipsis, but it always seems to truncate the end of the string (which is the more relevant part in my particular case). Is there any way to get it to automatically truncate the beginning?
Is there another control that I can use to display the path?
There is a project on The Code Project that looks like it does exactly what you want: Auto Ellipsis. There is a demo that you can download along with the source.
The easy way is do a trick by using textbox instead of label, just design it like a label then do this
textBox1.Enabled = false; //so it will not be selectable like label
textBox1.SelectionStart = textBox1.Text.Length; //so it will focus on the last character on the textbox

Categories

Resources