I had set of ASPX pages in which each page had different titles, but I want to put default title for pages which don't have a title. The default title must be configurable.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
You can do this:
Set the aspx header something like this
And in code behind put this inside the page load event:
I hope this will help you
This is helpful
I had a similar problem and none of these solutions worked well for me. The problem stems from the order control events fire for a page. In my case, I had some code that needed to be in the Page_load event (this was because that is the first event where we have a Request object to work with). That code also needed to run before the title could be set. Other pages in my site were able to simply set the desired Title in the page Ctor but because this page needed to interrogate the response object for information first, it was a problem. The problem with this is that the master page has already created the page header section by the time we get to the Page_load event and I didn't want junk in my Master page that was only required for a single page on my site. My simple hack to overcome this issue was to insert a bit of javascript inline in the content portion of the page:
With this in place, you are free to set the Title in the Page_Load event and it'll be set as soon as this line of code has downloaded. Of course, my site already has a JS requirement so if you're trying to avoid that then this is not going to work for you.
If this is classic ASP.NET (not MVC) and you are using
MasterPage
then you can set default title inPage_Load
event inMasterPage
:In your master page code behind, you could set
[this.Title = "Whatever";]
or you could also specify the default title in the HTML.