Title is Literal or String?

pswg

Member
Joined
Feb 26, 2008
Messages
9
Programming Experience
5-10
This code throws compilation error:
VB.NET:
Public Sub Page_Load()
    title = "Test"
End Sub
Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Literal'.


So I changed it. Now, it compiles fine in the IDE but when I try to debug it, I get the error:
VB.NET:
Public Sub Page_Load()
    Dim lit As Literal = New Literal()
    lit.Text = "Test"
    title = lit
End Sub
Value of type 'System.Web.UI.WebControls.Literal' cannot be converted to 'String'.

So... What's going on here, and how do you set the page title?
Thanks in advance.
 
BTW I also tried this:
VB.NET:
Public Sub Page_Load()
    title.Text = "Test"
End Sub
'Text' is not a member of 'String'.
 
When you use or add a Web Form and double click it you get this:
VB.NET:
Partial Class Default1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
    End Sub
End Class
Both Me.Title and Title and Page.Title is valid here and these refer to a String type property.
 
Right, I was missing the 'Handles' clause.

But I think the compiler problems were coming up because I had added a <asp:Literal ID="title" /> to my code. I deleted it once almost immediately, but VWD (the internal compiler and intellisense) still saw title as a Literal. I had to delete the page entirely and start from scratch before it would actually compile.
 
I see, didn't think of that. Anyway, using Page.Title there would be no confusion for the compiler what reference you meant even if a "title" object also existed within the class.
 
Back
Top