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
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