Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

CurrentPage.PageName in a unit

Vote:
 

Hi!

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"] %>?

 

Many thanks!

#54997
Nov 15, 2011 8:36
Vote:
 

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.

#55000
Nov 15, 2011 10:12
Vote:
 

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. :)

#55001
Nov 15, 2011 10:13
Vote:
 

And for your second question: There's no difference. PageData.PageName returns (((string) this["PageName"]) ?? string.Empty);

#55002
Nov 15, 2011 10:14
Vote:
 

That's a real race condition Erik, I beat you and you beat me :)

#55003
Nov 15, 2011 10:15
Vote:
 

Ah ok, I get it. Ok, anything negative with deriving from EPiServer.UserControlBase?

#55005
Nov 15, 2011 10:51
Vote:
 

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.

#55006
Nov 15, 2011 11:00
Vote:
 

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.

#55007
Nov 15, 2011 11:13
Vote:
 

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.

#55017
Nov 16, 2011 0:44
Vote:
 

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.

#55019
Nov 16, 2011 7:56
Vote:
 

Ok, thank you, both of you. Great help.

#55024
Nov 16, 2011 9:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.