HTML in Code Behind

How can I achieve this in code behind using VB?
Dim String AS String
String = "Some text <font-color="red"> the red text </font> the rest of the text."
mackeyrjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kishoreb123Commented:
yes. we need to come out of the sprinkling of html code in code behind like we used to do it in classic asp.
i would suggest to use a 'literal' or 'label' control to display html & this control text can be altered from code behind
0
mackeyrjAuthor Commented:
I have never used a literal The problem with using a lable is that the string is built by clicking on 9 options.
So I won't know where the label (literal) will appear.

Any explanation us using a literal for this purpose would be helpful.
0
kishoreb123Commented:
for example if a label control is created on aspx page with id label1, then you can refer the same in code behind & change the value like

dim param1,param2 as string
label1.text =param1 & "some text " & param2

you can change the other properties of label1 control using the properties window at design time or by specifying the properties in code behind to affect in run time.

http://www.startvbdotnet.com/aspsite/controls/label.aspx

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

mackeyrjAuthor Commented:
So now I am doing
Public wordOr As Label = New Label

With wordOr
                    .Text = "OR"
                    .ForeColor = System.Drawing.Color.Red
                End With
                Session("ReportDate") = vbCrLf + wordOr.Text + vbCrLf + "Date"

The label with the word OR shows up where I want it, but the color is not set to red.

0
kishoreb123Commented:
the following works for me..
Partial Class test
    Inherits System.Web.UI.Page

Protected Label1 As New System.Web.UI.WebControls.Label


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

With label1
                .Text = "Hello label"
                .ForeColor = System.Drawing.Color.Red
                End With
		
form1.controls.add(label1)


End Sub

end class

Open in new window

0
mackeyrjAuthor Commented:
I ended up using a literal control.
Since I will be changing the text color of only some words in the string and the position of those words could change.

Partial code:
Literal1.Text = "
" + Session("ReportNumber") _
                + " And " + Session("ReportDate") + "
"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.