This is going to sound trite, but the behavior is by design and not a bug. When a partial page is initalized, a copy of the PageData dictionary is passed to it, which is why the values remain unaffected in the original page.
To share values across pages and partials for the lifecycle of a request, you could use Context.Items. Alternatively, you could drop in a dictionary or an ExpandoObject inside PageData and use that to share values:
ueqt
Member
15 Points
9 Posts
Is this a bug in WebMatrix PageData?
Mar 29, 2011 09:42 AM|LINK
I met the same problem as follow link:
http://stackoverflow.com/questions/5127284/is-this-a-bug-in-webmatrix-pagedata
The answer to this link is only available to "from a content page to a layout page",
but I need "from a content page to a partial page", it still cause the problem.
Any solution? thanks.
trolis
Member
102 Points
43 Posts
Re: Is this a bug in WebMatrix PageData?
Mar 29, 2011 01:29 PM|LINK
yeah, i'm interested in this "bug" too.
I have partial page "xxx.vbhtml" and in it I have PageData("yyy")="xxx"
and in calling page I use @RenderPage("xxx.vbhtml"), to get code in xxx.vbhtml running.
So if I check PageData("yyy") after RenderPage function is used, PageData("yyy") is still nothing... :(
pranavkm
Participant
796 Points
106 Posts
Re: Is this a bug in WebMatrix PageData?
Mar 30, 2011 02:51 AM|LINK
This is going to sound trite, but the behavior is by design and not a bug. When a partial page is initalized, a copy of the PageData dictionary is passed to it, which is why the values remain unaffected in the original page.
To share values across pages and partials for the lifecycle of a request, you could use Context.Items. Alternatively, you could drop in a dictionary or an ExpandoObject inside PageData and use that to share values:
@{ Page["Shared"] = new Dictionary<string, string>(); Page.Shared["Title"] = "Test"; @Page["shared"]["Title"] @RenderPage("~/Partial.cshtml") @Page.Shared["Title"] } // Partial.cshtml @{ Page.Shared["Title"] = "Updated title"; }trolis
Member
102 Points
43 Posts
Re: Is this a bug in WebMatrix PageData?
Mar 30, 2011 05:44 AM|LINK
Thanx, that changes my logic a bit.
I just wanted to have some shared "include", where all initialization is done and some global variables are created and initialized...
ueqt
Member
15 Points
9 Posts
Re: Is this a bug in WebMatrix PageData?
Mar 30, 2011 07:10 AM|LINK
Thanks for your reply.
Although it looks strange,it what I needed.
And as it sounds trite,which site can I found the solution directly?
nevcook
Member
2 Points
1 Post
Re: Is this a bug in WebMatrix PageData?
May 12, 2011 10:47 PM|LINK
Thanks for the answer, and it makes sense, but that behaviour is far from obvious.
Where in the documentation / MSDN / whereever else woudl I have gone to find that out?
Mikesdotnett...
All-Star
154951 Points
19870 Posts
Moderator
MVP
Re: Is this a bug in WebMatrix PageData?
May 13, 2011 04:48 AM|LINK
You can use the AppState dictionary for global variables:
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter