PDA

View Full Version : Master pages problem



dimitrod
03-09-2006, 10:08 AM
I am evaluating the master pages feature of spring.web and I wrote an ascx template and an aspx page.
In the template I have 3 ContentPlaceHolders. When I run the application I get the following exception:


............
ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.]
System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length) +0
System.Web.UI.ControlCollection.CopyTo(Array array, Int32 index) +52
Spring.Web.UI.MasterPage.Initialize(Page childPage) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Web\UI\MasterPage.cs:49
Spring.Web.UI.Page.OnInit(EventArgs e) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Web\UI\Page.cs:209
Default.DefaultForm.OnInit(EventArgs e) in c:\Inetpub\wwwroot\Test\Default.pas:74
System.Web.UI.Control.InitRecursive(Control namingContainer) +233
System.Web.UI.Page.ProcessRequestMain() +197
............


If I delete on of the ContentPlaceholders (no matter which of them) everything works as expected. Here is the code:

Template.ascx:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<spring&#58;Head id="head1" runat="server">
<title>TestApp</title>
<link href="<%= Page.CssRoot %>/default.css" type="text/css" rel="stylesheet" />
</spring&#58;Head>
</head>
<body>
<form id="form" method="post" runat="server">
<div id="topHeader">
<spring&#58;ContentPlaceHolder id="topHeader" runat="server" />
</div>
<div id="leftHeader">
<spring&#58;ContentPlaceHolder id="leftHeader" runat="server" />
</div>
<div id="body">
<spring&#58;ContentPlaceHolder id="body" runat="server" />
</div>
</form>
</body>
</html>



Default.aspx


<body>
<spring&#58;Content id="topHeader" contentPlaceholderId="topHeader" runat="server">Top Header</spring&#58;Content>

<spring&#58;Content id="leftHeader" contentPlaceholderId="leftHeader" runat="server">Left Header</spring&#58;Content>

<spring&#58;Content id="body" contentPlaceholderId="body" runat="server">Body</spring&#58;Content>
</body>



Web.xml


<?xml version="1.0" encoding="iso-8859-1" ?>
<objects xmlns="http&#58;//www.springframework.net">

<object id="standardPage" abstract="true">
<property name="MasterPageFile" value="~/Template.ascx" />
<property name="CssRoot" value="css" />
</object>

<object type="~/Default.aspx" parent="standardPage" />

</objects>


Do you have any clue why I am getting this exception?

LaTtEX
03-10-2006, 02:56 AM
This is a stab in the dark but, have you tried changing your object definition below to:


<object type="Default.aspx" parent="standardPage" />

Remember that if your object type is an aspx and you don't have an alternate id, the object takes as its id the value of type.

I suspect the "~/" characters might be escaping something in the page definition, or something doesn't get initialized properly with those characters in the object id of the page.

dimitrod
03-10-2006, 07:03 AM
Thanks for your suggestion. I tried changing my page object definition to

<object type="Default.aspx" parent="standardPage" /> but with no luck. What really puzzles me is that it works with 2 placeholders but adding a third raises the exception.

Aleks Seovic
03-10-2006, 10:07 AM
Thanks for catching this -- there was a bug in MasterPage implementation:



Control&#91;&#93; controls = new Control&#91;this.Controls.Count&#93;;


should be changed to:



Control&#91;&#93; controls = new Control&#91;childPage.Controls.Count&#93;;


Sorry about that, I somehow missed it when I refactored master page code out of the Page class. Basically, it works as long as your master page has the same number or more controls than the child page, but as soon as the number of controls on the child page exceeds the number of controls on the master page, it crashes miserably.

Pretty nasty bug if you think about it, although very obvious when you look at the code...

Thanks,

Aleks