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?
 
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
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.