Please can someone give me some input on <%= CurrentPage.PageName %> (for example) in an ascx file. Is it supose to work? For me, some times it does and some times it doesnt. I find it very strange. At home in my development enviroment it works fine for instance to write <title>My site - <%= CurrentPage.PageName %></title>. But at some instances here at work, it doesnt work. What am I missing?
Also, it would be nice to know: what is the difference between <%= CurrentPage.PageName %> and <% CurrentPage ["PageName"] %>?
Are all the user controls you are testing derived from EPiServer.UserControlBase? If you create a default user control in visual studio it will derive from System.Web.UI.UserControl which does not define CurrentPage.
You need to inherit from EPiServer.UserControlBase to user CurrentPage in a usercontrol.
And I don't think there is any difference between using CurrentPage.PageName vs CurrentPage["PageName"], it's just more beautiful with .PageName. :)
And for your second question: There's no difference. PageData.PageName returns (((string) this["PageName"]) ?? string.Empty);
That's a real race condition Erik, I beat you and you beat me :)
Ah ok, I get it. Ok, anything negative with deriving from EPiServer.UserControlBase?
Not really, other than you can't reuse the UserControl on a page that does not inherit from PageBase. But if you want to use CurrentPage that is what you'll do anyway. If you want your control to be more generic (use it outside EPi projects etc) you must have some other way of storing the "Page name", e.g. a property on the UserControl that you set from the page.
Ok ok. I will put some more thoughts into it at home later when Iam not so busy. Probebly will have some more questions then. =)
Many many thanks for now. Very helpful. I try to juggle various work tasks and study .net at home.
Magnus: ok, this might be a silly question, but how do I see if a page inherits from PageBase? In the code behind for an aspx file it says "public partial class StandardPage : EPiServer.TemplatePage" or "public partial class WebForm1 : System.Web.UI.Page".
Iam guessing that the first one inherits from PageBase but not the later right? CurrentPage didnt seem to work in the later.
Correct, TemplatePage inherits EditPage which inherits SimplePage which inherits PageBase :) In Visual Studio, right click TemplatePage in your class definition and select go to definition which will open up the object explorer where you can continue to explore the inheritance.
Ok, thank you, both of you. Great help.