开发者

Changing page title dynamically depending on a databinding result (ASP.NET)

开发者 https://www.devze.com 2023-01-21 07:09 出处:网络
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.

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开发者_StackOverflow中文版 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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号