Setting the page title in asp.net
Wednesday 30 September 2009
If you are retriving your title text from a database and want to set it to the pages title tags (<title></title>) then here's an easy way to do it:
-
Page.Title = "Title Text"
Here's an example of this in use:
- Dim MyConnection As SqlConnection
- MyConnection = New SqlConnection()
- MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
- Dim sql As String = "SELECT Title FROM TABLE WHERE ID = 1"
- Dim objDR As SqlDataReader
- Dim CmdR As New SqlCommand(sql, MyConnection)
- MyConnection.Open()
- objDR = CmdR.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
- While objDR.Read()
- Page.Title = objDR("Title").Trim()
- End While
- MyConnection.Close()
|
(1)
|
|
|