Using a VB.Net variable in an outlook HTML body - html

I am using the following code that should write a HTML body for an outlook email, but where I am using a variable, the HTML uses the variable tag instead of the value. How do I get it to use the value instead of thinking it's part of the HTML?
Code
<p class="MsoNormal"><span style='color:#1F497D'> NameOfPerson has added AmountOfNewEntries to the database</span></p>
NameOfPerson and AmountOfNewEntries should display their values and not the actual text.
I've tried using <#%NameOfPerson#%> but it errors saying that the tag needs to be closed, assuming it is a HMTL tag.
Thanks

Assuming that the variables refer to XElement objects, and you need to pass the value of those elements as strings into HTML to form part of the body of the email, maybe you could use String.Format and the Value property of XElement as below?
String.Format("<p class=""MsoNormal""><span style='color:#1F497D'> {0} has added {1} to the database</span></p>", NameOfPerson.Value, AmountOfNewEntries.Value)

Related

How to pass a Break in a string variable in Typescrip/Angular and bind that string to <p> tag

Let's say I have a variable in my typescript class called description and the type is String.
And what I want is that I can pass HTML elements inside the description variable, specifically I want to be able to pass new lines. And that I can add the string tag to a paragraph tag and that is aplies the html inside the string
I tried to put '\n' and also <br> in the description variable but I did not get the result I wanted. All the text was still outputted in one line.
This is the html btw:
Result:
Is it Possible what I want and know. If not what could be better alternatives for this problem.
You can bind to the innerHtml of the element, which should render your <br> tags:
<p [innerHtml]="description"></p>
You can do something like this which all allows you to pass in html in your variable https://medium.com/#swarnakishore/angular-safe-pipe-implementation-to-bypass-domsanitizer-stripping-out-content-c1bf0f1cc36b

How to render value from database as HTML

Is it possible to reneder value from any external source (database, files, etc.) like 'some text' on page as pure HTML with using LIT-HTML? I'm trying to do it by assinging this value to variable like that:
var variable = html `{$database.value}`
but it doesn't work. I still see text on the page instead of HTML tags (div, a)
You can use the unsafeHTML directive for this: https://lit-html.polymer-project.org/guide/template-reference#unsafehtml

ASP.NET MVC4 - display HTML containing string as raw HTML

I have a string, read from a database, that contains HTML that I want to output. Despite applying HttpUtility.HtmlDecode(), the View always renders the string as encoded HTML (i.e. <SPAN> instead of <SPAN>).
I am using:
string test = WebUtility.HtmlDecode(myStr);
<span>#test</span>
I have tried:
string test = HttpUtility.HtmlDecode(myStr);
<span>#test</span>
<span>#HttpUtility.HtmlDecode(myStr)</span>
Use Html.Raw()
#Html.Raw("<span>Hello</span>")
All the output from helpers and other elements in Razor are put through HttpUtility.HtmlEncode, unless they implement IHtmlString. But your best option here is using Html.Raw()
You need to use #Html.Raw:
#Html.Raw("<h1>Header</h1>")
Will output the text Header.
Try this helper method
#Html.Raw(myStr)

HTML inside TextArea?

So I have this textarea in my website. By default, it has something like this as its contents:
Name : Sample Value
Age : Sample Value
Location : Sample Value
It is editable before the user hits the button and inserts it into the database, although I am not using a rich text editor since it's nothing but a simple text.
Since basic HTML codes are not browser readable inside the textarea tag, I used
to separate lines.
Now my problem is that I am not able to include the HTML code when I'm reading the value of the textarea tag in the server side.
Thus, the value inserted to the database is not HTML formatted as well, and when it is once again fetched into a web browser, it has no format at all.
What alternatives do I have? Thanks.
Not possible using textarea, use contenteditable DIV instead.
<div contenteditable="true"></div>
You can use getters and setter as shown below:
//Get content
var contents = document.getElementById("divId").innerHTML;
//Set content
document.getElementById("divId").innerHTML = contents
Here is the browser support for this approach.
Why don't you use JQuery and do this $(textarea).val() to get the value of the textarea as a string and use it server side. you might have to consider using Ajax to make a call to the server side method you want to pass the Html data.
The answer is very simple.
Use contenteditable DIVs instead of TextBox and TextArea.
But remember to add contenteditable="false" to all your inner HTML tags.
This worked for me.

Emit raw html in ASP page?

This is extremely aggravating. I just want to simply insert raw html. I can't use the literal control because there's no ignoring the quote character. I don't want to use a script element because I'm adding it in a ascx file. I just want raw html output. Is there no operater for this?
I've properbly misunderstood you completely but:
In Classic ASP it is:
<%=("<div style=""color:red;"">html</div>")%>
output:
<div style="color:red;">html</div>