Link to home
Start Free TrialLog in
Avatar of mackeyrj
mackeyrj

asked on

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."
Avatar of kishoreb123
kishoreb123

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
Avatar of mackeyrj

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of kishoreb123
kishoreb123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

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

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