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."
Dim String AS String
String = "Some text <font-color="red"> the red text </font> the rest of the text."
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
ASKER
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 = "
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") + "
"
+ " And " + Session("ReportDate") + "
i would suggest to use a 'literal' or 'label' control to display html & this control text can be altered from code behind