Setting the page title in asp.net




Setting the page title in asp.net
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:
  1. Page.Title = "Title Text"  
Here's an example of this in use:
  1. Dim MyConnection As SqlConnection   
  2. MyConnection = New SqlConnection()   
  3. MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString   
  4.   
  5. Dim sql As String = "SELECT Title FROM TABLE WHERE ID = 1"  
  6. Dim objDR As SqlDataReader   
  7. Dim CmdR As New SqlCommand(sql, MyConnection)   
  8. MyConnection.Open()   
  9. objDR = CmdR.ExecuteReader(System.Data.CommandBehavior.CloseConnection)   
  10.    While objDR.Read()   
  11.       Page.Title = objDR("Title").Trim()   
  12.    End While  
  13. MyConnection.Close()  


1 person likes this article, click here to say you like this article too (1)
Send a link to this page via email Send a link to this page