Article Title name in browser

Last post 09-22-2008 12:59 PM by JamesSAEP. 6 replies.

Sort Posts:

  • Article Title name in browser

    09-15-2008, 1:29 PM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

    I'm not sure what it is called that I'm after, but I'll do my best to describe it... :)

    I have a database with hundreds of records.  When I look at the details of a record (details are views in either a FormVIew or ListView).  At the top of the browser, in the TAG area, I think, is displayed:

    "My Site - Inventory: Item Details".

    What I want to do is extend this TAG so that the Item Name is displayed like so:

    "My Site - Inventory: Item Details - Part Name Here"

    All my items are in SQL 2008 database.

    How do I do this using C# with 3.5 .net?

     

    Thank you.

  • Re: Article TAG name in browser

    09-15-2008, 4:44 PM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

     After spending the past few hours on this, I have found that what I'm after is trying to get a "Dynamic Title" to work. I've found several articles out there and have gotten a basic title override to work.  What I want is to pull the name from a sql query that is bound to the Label ProducerNameLabel and have that as my title.

    This lable is inside a FormView, so what I have so far in the code-behind for the Page_Load is:

    title = ((Lable)FormView1.FindControl("ProducerNameLabel"));
    Page.Title = title;

     This gives me the following error:

    The name 'pagetitle' does not exist in the current context

     

    Any help would be great.

  • Re: Article TAG name in browser

    09-15-2008, 5:35 PM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

     I've gotten a little further:

            string pagetitle = (Label)FormView1.FindControl("ProducerNameLabel");
            Page.Title = pagetitle;

     

    But this errors:

    Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'

     

    How do I convert this?

  • Re: ArticleTitle name in browser

    09-15-2008, 6:02 PM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

     Trying to use:

            string pagetitle = FormView1.FindControl("ProducerNameLabel").ToString();
            Page.Title = pagetitle;

     

    This will display the page, but the title shows:
    "System.Web.UI.WebControls.Label"

     I've got to be close....?????????????????????

     

  • Re: ArticleTitle name in browser

    09-15-2008, 6:55 PM
    Answer
    • All-Star
      30,593 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 5:53 PM
    • Dhaka, Bangladesh
    • Posts 3,306
    • Moderator
      TrustedFriends-MVPs

    Label lbl = (Label)FormView1.FindControl("ProducerNameLabel");

    [Or: Lbael lbl = (Label)FomrView1.Row.FindControl("...");    try both and choose the one that works]

    and then:

    Page.Title = lbl.Text;

     

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: ArticleTitle name in browser

    09-16-2008, 11:15 AM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

     Thank you for this.  I used the first solution.

     

     

  • Re: ArticleTitle name in browser

    09-22-2008, 12:59 PM
    • Member
      66 point Member
    • JamesSAEP
    • Member since 01-15-2008, 11:51 AM
    • Posts 237

     Ok, I have found a problem with using this code on the "Page_Load" code-behind:

                Label lblProdcucer = (Label)fvAdditionalInformation.FindControl("Label1");
                Label lblItemName = (Label)fvAdditionalInformation.FindControl("Label3");
                Page.Title = string.Concat("Now Viewing: Item Information", " >", " ", lblProdcucer.Text, " ", lblItemName.Text);   

     

    This works great if I'm viewing a page that I'm viewing has information for the "label1 and Lable3" to display.  But what If there isn't  anything in the database for either of thes (null values)?

    How can I code it so that:

    if either is null....
    Response.Redirect ("~/default.aspx");

    Thanks.

Page 1 of 1 (7 items)