SaaS CMS has officially launched! Learn more now.

Properties in page lifecycle?


I have a control within a page which needs a value to be passed to it but when I try and put in an episerver value it cant see it?

<uc2:NowPlaying ID="myControl" runat="server" ArticleID=<%# CurrentPage["testString"].ToString() %> />

but the follwoing works fine

<uc2:NowPlaying ID="NowPlaying1" runat="server" ArticleID=90 />

The control needs the property from th epage to work, I cant put the property in the control as sometimes its not the data from teh current page which will be used.

May 22, 2008 12:53

It is probably a data binding problem in ASP.NET, the property in the PageData object should be there if it has a value. The <%# tags requires databinding to be evaluated, the second example code does not require databinding.

May 22, 2008 13:27

Yes the value is there in the aspx page when I dubug but its not pusing through to the ascx control? I was wondering if its trying to render the control before evaulating the property which is needed within it or something?

May 22, 2008 13:41

Could be, where are you databinding (the actual call to DataBind()) and where is the logic done in the NowPlaying? By "where" I mean in which event in the page life cycle.

A quick fix is to assign ArticleID in the OnInit event in code behind instead.

May 22, 2008 15:45

I tried this

Episerver property = <EPiServer:Property ID="Property1" runat="server" PropertyName="test" /><br />

ASP Literal = <asp:Literal ID="test" runat="server" Text=<%# CurrentPage["test"].ToString() %> /><br />

and it outputs the following

Episerver property = 87
ASP Literal =

 So why are they outputting differant things when they referance the same property??

May 22, 2008 15:49

Im not databinding, its a property of the page not a list or something?

May 22, 2008 15:54
I hav ejust called databind on my control and it works? Why Do I need to call that when its a property of the page? Does databind have to be called on EVERYTHING then?
May 22, 2008 16:01

Well, <%# is the magic ASP.NET keyword for databinding, it will not be evaluated if you don't call DataBind. Otherwise just assign the values from code behind instead.

Edited, May 22, 2008 16:10
* 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.