November Happy Hour will be moved to Thursday December 5th.

Placing a web user control inside a pagelist

Vote:
 
This one is driving me mad as I feel I've tried everything. However there must be something (hopefully something simple!) that I'm missing. Basically I have a pagelist that contains amongst its properties a url for an image and a url for a flash object. Depending on what is set for each item, I want to be able to produce code for either an image or a flash object at that point. I've been attempting this using a web user control within which I make visible the appropriate chunk of html depending on the values of the image and flash properties. This approach works well outside of a list, but within one I'm having difficulty accessing the appropriate property. I could ramble on, so if anyone has any ideas about how to best achieve this I'd like to hear them. My current fix is to call a function within the list that passes the properties along and returns the appropriate string, but I don't like having the html in the codebehind at all and would definitely prefer a solution that will allow our interface people to edit it.
#12543
Mar 08, 2006 22:59
Vote:
 
Query your parent recursively for the IPageSource interface. Inside a pagelist, IPageSource.CurrentPage returns the page you're currently iterating. On a page, it will return the page itself (PageBase.CurrentPage). This is how the Property control knows how to render a property from a page in a list, or the page, depending where you put the property control in your markup. /Steve
#14470
Mar 09, 2006 9:11
Vote:
 
And here is some code from a user control that sometimes is showed on a template control and sometimes on a ordinary page. /// /// If there is a control implementing the IPageSource /// interface higher up in the control hiearchy /// the actualPage will be set to the current page of that control. /// If no such control is found the actualPage will be set to /// the CurrentPage of this control. /// /// If a control is found this would imply that a templated control /// is using this user control (for example a page list). Then we /// are interested of the page currently being iterated in the /// templated control, not the page containing /// the templated control. /// /// private void SetActualPage(Control control) { if ((control.GetType().GetInterface("IPageSource") != null)) _actualPage = ((IPageSource) control).CurrentPage; else if (control.Parent == null) _actualPage = CurrentPage; else SetActualPage(control.Parent); } private void Page_Init(object sender, System.EventArgs e) { SetActualPage(this.Parent); }
#14471
Mar 09, 2006 15:00
Vote:
 
Thank you! That works beautifully.
#14472
Mar 10, 2006 13:20
Vote:
 
It always makes me happy when I see people use the IPageSource interface. This means that they have understood how a lot of things works, both in ASP.NET and in EPiServer. The future is bright, keep up the good work, and have a great weekend :-) /Steve
#14473
Mar 10, 2006 13:40
* 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.