Label in <title>

D

DC

In HTML page, I put:

<html>
<head>
<title>Article: <asp:Label ID="lblHTMLTitle"></asp:Label> </title>
....

In the code behind:

....
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Protected WithEvents lblHTMLTitle As System.Web.UI.WebControls.Label
....
cmdSQL = New SqlCommand(sSQL, connADO)
connADO.Open()
cmdReader = cmdSQL.ExecuteReader
If cmdReader.Read() Then
lblHTMLTitle.Text = cmdReader.Item("Title").ToString()
...
.....

But each time it hits: lblHTMLTitle.Text =
cmdReader.Item("Title").ToString(), it gives me the following error message:
Object reference not set to an instance of an object.

Any ideas why is this happening?

Or can't <asp:label> put in <title> tag?
 
H

Hermit Dave

instead of using label in <title>
set the title as
<title id=myPageTitle>

in code behind..
System.Web.UI.HtmlGenericControl myPageTitle;

in page load
if(!Page.IsPostBack)
{
myPageTitle.InnerText = "My Page title is dynamic";
}

try something like this....
 
M

mikeb

Hermit said:
instead of using label in <title>
set the title as
<title id=myPageTitle>

in code behind..
System.Web.UI.HtmlGenericControl myPageTitle;

in page load
if(!Page.IsPostBack)
{
myPageTitle.InnerText = "My Page title is dynamic";
}

try something like this....

Don't forget that the <title> tag needs a runat="server" attribute:

<title id="myPageTitle" runat="server">
 
C

Chad McCune

I dont know about anyone else..but it seems like VS.Net always removed my
runat="server" attribute on my title tag...I've stopped doing it that way
and use a placeholder now instead...

Chad Mccune, MCSE, MCDBA
 
H

Hermit Dave

oh shite.. forgot that... sorry... was about to leave for home then...

--
Regards,

HD

Once a Geek.... Always a Geek
 
H

Hermit Dave

sorry mate was in a bit of hurry... my bad..
thanks for correcting...

--
Regards,

HD

Once a Geek.... Always a Geek
 
G

gerry

yep , same here , a real pita , have to reinsert the runat="server" anytime
the page ( code behind I believe ? ) is edited and saved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top