views:

22

answers:

1

Hi, I'm newbie in ASP.NET

I have a page to show a thread content, it take the ID of the thread from the query string.

depending on the ID, I show the content using the FormView control.

how could I then change the page title depending on the databinding result?

I've figured out that I can do that before the databinding in the Page_Load event, by querying the title of the thread depending on the ID from the QueryString object, but I'm wondering if I can achieve my goal during the databinding!

And here is an important question! does changing the page title dynamically affect the SEO?!

Many thanks :)

+2  A: 

Yes, you can set the Page.Title during databinding.

Remember, per the documentation, The page must contain a head element that has the attribute runat="server", otherwise the title will not render.

You can set the Title at any point in the page lifecycle that you can set other values (such as the text of a label, etc). This is anything before the Rendering stage. Of course, if you do it in the Init stage, then there's the risk that when the Viewstate is applied, your changes will be overwritten, but you should be fine in the Page_Load, or in control event handlers.

Databinding happens in the control's ItemDatabound or corresponding event handler (depending on the control in question), so you're fine.

David Stratton
as David points out, in your CodeBehind you can set the Page.Title value to anything you want such as "Viewing Thread " + threadID
adam
Many Thanks dear, is that process affects the SEO? I want my site SEO Friendly!
Hashem AL-Rifai
I'm sorry, a small question: could I change the title inside the FromView template markup? Thanks man
Hashem AL-Rifai
No, because the Title is in the HEAD of the html document generated by the page. The FormView is inside a Form in the BODY of the html page.
David Stratton
Ok Thanks, still the SEO Question ;)
Hashem AL-Rifai
I'm not sure I'm the one to answer that. I have little concern for that in my practice, as I build mostly internal web apps. Maybe poost that as a different question? "Will changing my page title dynamically affect SEO"? I'm just the wrong guy to ask on that.
David Stratton