Usercontroll overkill

Hi, with experience from other CMS systems, I must say I think EPiServer is using way too much usercontrols. I'd say that usercontrols is most usefull when you think about re-use. For example; I trying to set the page title on my website by using the function <%=gettitlestring()%></%=gettitlestring()%>. Now - this should in reality be very simple, right? (Pseudo code) title = Configuration["EPsSiteName"] + CurrentPage.PageName return title Unfortunately CurrentPage and Configuration extends UserControlBase. Therefor I can't have this code in the Masterpage since it extends MasterPageBase. Then I try something like this; PageBase page = (PageBase)Page; title = ConfigurationSettings.AppSettings["EPsSiteName"] + page.CurrentPage.PageName Running the website I get the folloing error: Unable to cast object of type 'ASP.default_aspx' to type 'EPiServer.PageBase'. Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.default_aspx' to type 'EPiServer.PageBase'. Source Error: Line 33: PageBase page = (PageBase)Page; Surely there MUST be a way of outputting site name + page name without using User Controls? I really want this code in the Code Behind file of the MasterPage..... Regards Seeven
Feb 08, 2007 11:35
Your code should be working if the default.aspx extends a EPiServer page like TemplatePage or SimplePage.
Feb 08, 2007 12:24
Can't really see that the error you're getting has anything to do with user controls (or the number of user controls). The UserControlBase class also require that the underlying Page is of the type PageBase (or a decendant). But, I'll agree with you on the matter that there is too many user controls in the sample site. Personally I think this is a bad idea, and just makes the number of files and classes in the system grow to something that is hard to handle. However, the 1.1 version of the sample site uses the Content Framework classes, which is a pre-2.0 version of Master Pages, and these did not play well with the designer in Visual Studio. Hence, most of the logic was extracted to user controls, which works ok. Quite a few people like to work in the visual designer in Visual Studio, and this was the solution. Hopefully, the next version of the sample site (for v5) will have another file layout. /Steve
Feb 08, 2007 15:24
Did you get it to work Steven? I have a similar situation. I also would like to access CurrentPage in the masterpage codebehind. - Jonas
Apr 23, 2007 11:23
Is this what you looking for? PageBase page = (PageBase)Page; page.CurrentPage ...
Apr 23, 2007 13:12
* 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.