Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Database queries in title

    How can I display text in the <title> of an .aspx page by retreiving it from a database using a querystring to determine which record. For example, on this forum when you view a thread, the title of that thread appears as the title of the page.

    Any help would be appreciated. Thanks.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Assuming you can do the query portion, just check the querystring value and make sure it's not null. If it's not, pass it to a function that grabs the title from the db and you're done

    Some method in your codebehind:
    Code:
    protected string getTitle(int id)
    {
    	// do some db query to grab this
    
    	return "this is a title for " + id.ToString();
    }
    Then in your html:
    Code:
    <title>
    	<% Response.Write((Request.QueryString.Get("id") != null) ? getTitle(Convert.ToInt32(Request.QueryString.Get("id"))) : "default title"); %>
    </title>
    Good luck;

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thanks for the help. I did it a bit of an easier way in the end, but thanks for putting me in the right direction.

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by CurtWRC
    Thanks for the help. I did it a bit of an easier way in the end, but thanks for putting me in the right direction.
    Don't be shy

  • #5
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Well the way I did it before was by just putting:

    <title>
    Query_DB(Select ...)
    </title>

    But that just displayed it as text. However by putting:

    <title>
    <% Response.Write(Query_DB(Select ...)) %>
    </title>

    Then it worked.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •