Sending SMS text with line break/new line - c#

I am developing SMS portal in asp.net c# where people register & send sms.
I M Using multiline asp:textbox for input message. i want to break line where user hit enter/new line in textbox. help me if there any textboxeditor which support only <br/> or any other solutions.

from my own experience the default asp:textbox control with TextBoxMode=MultiLine; which automatically adds \r\n for line breaks will do the trick and no additional edit is needed
and html tags like </br> is not processed .

Use textarea tag and escape text on the server side. Replace each line break with </br>, but other tags show as plain text or add some validation.

Related

ASP.NET HTML Encoded Data-Bind and br tag

I'm trying to encode data that is to be displayed on a separate page (.aspx) after a user submits a form with their information and questions. There are both text input and textarea fields that the user can fill out.
I'm using the <%#: %> expression to place this data on the page since it does the HTML encoding, but have run into an issue with the encoding also encoding the br tags as text instead of actual line breaks.
Is there a way to make it so that the br tags still cause a line break, but leave everything else encoded using this method?
Example of user input:
Hi
This is what should be responded with.
Here is an example of the code that places it on the page:
<p><%#: ((DiscussionThread.Discussion)Container.DataItem).Text %></p>
What it currently displays on the page:
Hi<br /><br />This is what should be responded with.
Thanks in advanced!
Don't know, will it help you in your case or no, but I always use next way:
string forInput = yourTextBoxID.Text.ToString().Replace(Environment.NewLine, "%NL%");
string forOutput = forInput.Replace("%NL%", Environment.NewLine);
If in forOutput Environment.NewLine will not work, change it to <br />
%NL% it is just a identificator, u may change to anything else.

Unable to insert a tab spacing with \t

I'm trying to do a password recovery with SMTP. In the email, i've added some necessary text and hyperlink for the user to recover their password. As you can see the code here, i've added a hyper link.
strBody.Append("Click here to change your password.");
In order to add a non-hyperlink text, i added this statement behind the code.
strBody.Append("Click here to change your password. \t\t\t\t This is a computer generated email for your password recovery. \t\t please do not reply this email.");
I've added a \t in the string but instead it doesn't show any tab spacing in the email. What have i done wrong here?
The fact that you have HTML in your body makes me assume that you are sending HTML emails. If this is the case then your tabs will be in the source but HTML collapses all whitespace which includes tabs.
You'll have to either use proper HTML to indent your text (eg margins on block elements) or use plain text where tabs and such like will work.
There are no tabs in HTML. That \t is a Windows character code. You'll need to either throw a <span style="margin-left: 1em;"> around the text or use (many times).
I think the right approach is this:
<span style=\"margin-left: 1em;\">This is a computer generated email for your password recovery.</span>
use multiple times instead of tabs in your html message body.
You're probably sending the email as HTML, therefore the tab (\t) will be rendered as a single space, which is normal.
Either change the email format normal (plain text) or add styling to mimic the indentation you want.
Tab characters inside <pre></pre> tags seem to survive.
I have not tried this in an e-mail yet, but you can give it a shot.
<pre>
a b c d
</pre>

How to make sure that my <br> tag get read as a html and not as text

I have a asp.net page. On one particular page i can add comments and when i add these comments they get saved to a db. When i want new lines the "\n" tagg is automaticly displayed when i look at it in my backend code.
So now when i get back a response i want to get my comments back but i want them to have breaking spaces on those particular places where the "\n" is displayed.
I tried this in my backend code(cs):
Text = text.replace("\n", "<br/>")
the result i get:
my test<br/> test text new line<br/>
My <br> tags get displayed as text.
To clarify i basicly wan to achieve this:
Why are my "<br />" tags getting converted to "<br />"?
But from the backend code in C#.
Ive been googling and haven't been able to find a answer to this.
If you are using ASP.NET WebForms and you are putting the text in a Label control, this is normal behaviour. The Label control html-encodes its text before rendering it.
The Literal control does not use html-encoding, so if you change your Label to a Literal, it should work.
If you are using ASP.NET MVC, try using #Html.Raw(Model.Text).
You need to create an HtmlString with your content before printing it. So your code would be like
var foo = new HtmlString(text.replace("\n", "<br/>"));
and you would print foo.

How to store multiline text in SQL Server 2008 keeping track of new line in asp.net

I am developing an intranet ASP.NET web site. I am saving user comments from an asp.net multiline textbox into a SQL Server database, and display exactly as it is written by user in Gridview.
Suppose a user enter following string:
1.Task1
2.Task2
3.Task3
then the retreived data in the gridview should be same as user entered it before saving.
While debugging, I tried replacing \r\n with <br/> but gridview is displaying <br/> as it is..not tasking a new line.
I am using c#.
I have found the solution for it Using Literal Control.
Now, there is one new Problem where i am not using Gridview.I am generating Comments as html and sending it as a mail body,
Suppose a user enter following string:
1.Task1
a.T1
b.T2
c.T3
2.Modules
a.Module A
b.Module B
c.Module C
Line Break <br /> when Replaced with /n is taking the content only to new line not taking spaces for Second Line Automatically.and the mail body html is generating it like this:
1.Task1
a.T1
b.T2
c.T3
2.Modules
a.Module A
b.Module B
c.Module C
Which is not what i Expect.
Please Help. Thanks.
You can use carriage returns when you save the text and when displaying it in the grid, you can replace it as
'<%# Eval("TheName").ToString().Replace("\n", "<br />") %>'

Using <br/> in tool tip and change the default color of a tool tip

I am using default asp.net ToolTip property, the text is
This is Going to be a long text
Thats why we decided to split it.
but using <br/> to split the line doesn't work, it renders as a text, and I want it to break the line instead.
Here is my code:
Label lblActionText = new Label();
lblActionText.Text = "Helloooo Phaltu";
lblActionText.Style.Add("cursor", "pointer");
lblActionText.ToolTip =
"This is Going to be a long text"
+ "<br/>"
+ "Thats why we decided to split it.";
I've not tried this but would "System.Environment.NewLine" not do the job instead of the BR tag?
You can use this to insert a line break inside a ToolTip.
lblActionText.ToolTip = " First text " + Environment.NewLine + " second text ";
Use the line break character entity (
). It is easy to implement but the only problem is that this will work in IE & Chrome but not Firefox.
lblActionText.ToolTip = "This is Going to be a long text
Thats why we decided to split it.";
See jsFiddle: http://jsfiddle.net/jafLf/
You are passing a string value to a Tooltip, and that's why the HTML element <br /> is not working.
However you can try this ASP.Net AJAX TooltipExtender
This works only on IE but other browsers are not!!
If you want to have a customize tooltip then seach for jQuery tooltips to have a formatted tooltip
You can do this with adding a table in the tooltip :)
Example: ASP forum
The ASP.NET ToolTip property corresponds to the HTML title attribute.
In IE and Chrome you can simply do:
<span title="multiline
tool
tip">Mouseover me!</span>
However, that won't work in Firefox as it actually follows the W3C guidelines for CDATA.
CDATA is a sequence of characters from
the document character set and may
include character entities. User
agents should interpret attribute
values as follows:
Replace character entities with characters,
Ignore line feeds,
Replace each carriage return or tab with a single space.
Your best bet (considering you also want to change the colour) would be to go with a jQuery solution such as QTip which gives you all the customisation you want and more..
You cannot change the color of a tooltip with the default title attribute. For that the only way is to use a javascript generated tooltip.
There are plenty of plugins for jQuery such as:
Dynamic tooltip
Popup Bubble
jQuery Horizontal Tooltips
Coda Popup Bubble
Awesomeness
TipTip
(mb)Tooltip
vTip
jGrowl
jQuery Ajax Tooltip
Digg-style post sharing tool with jQuery
Input Floating Hint Box
Simpletip
qTip
Orbital Tooltip
And many more, check them here: Stylish jQuery Tooltip Plugins Webdesign
You can also just create your own using javascript. Add a mouseover event on the element then show a hidden div over the element with whichever html elements you want, in whichever color you need.
It is also more safe to use a javascript approach for cross-browser compatibility.

Categories