here's the situation (product site): i have header.ascx, a page (let's say page.aspx), and footer.ascx. header.ascx builds the breadcrumb links for the categories and subcategories leading up to a product dynamically. page.aspx actually takes care of determining what is in which categories and such. footer.ascx takes care of the sub-navigation. the path of least resistance, of course, leads me to having to make a database call for each of these sections for each product page, meaning at minimum three calls to get the same information three times. QUESTION: is there any way for, say, header.ascx to call the database, retrieve the data, do with it what it will, and then pass it on to page.aspx to use, that then uses it, and then passes it on to footer.ascx, so that I don't have to make unnecessary calls to the db for info i've already retrieved? i tried thinking about a way to do it using objects, but how do you get them to persist between the files, or even pass them? I suppose an object would be the way to go, but how can you get it to survive between controls/pages? i'm using .NET 1.1 and VS.NET 2003. THANK YOU TO ANYONE WHO HELPS!
create a property in the header control public DateTime CreatedDate { get { return Convert.ToDateTime(ViewState["CreatedDate"]); } set { ViewState["CreatedDate"] = value; } } then in your header when you get the value from db, you just o CreatedDate = "datefromdb"; then in your page you just do HeaderControl1.CreatedDate; (where headercontrol1 is the name of your header control in the page)
Froggie - Thank you so much...I can't believe that I forgot about this method I assume, then, that I should be able to pass this to the footer, too, using the same method: [make property "db" for thePage.aspx, then in footer:] footerDB = thePage.db correct? i have to go to work, but I am excited about trying this when I get home
hey - so i tried your method, and i found out that it doesn't work, and i think it's because i'm not using the header/footer controls as actual controls in the page, but am actually dynamically loading them from a basepage class, ie: code for basepage: Public Class BasePage : Inherits System.Web.UI.Page Protected Overrides Sub OnInit(ByVal e As System.EventArgs) Dim header As String = Page.ResolveUrl("~/templates/header.ascx") Dim footer As String = Page.ResolveUrl("~/templates/footer.ascx") Me.Controls.AddAt(0, LoadControl(header)) MyBase.OnInit(e) Me.Controls.Add(LoadControl(footer)) End Sub End Class Public Class BaseControl : Inherits System.Web.UI.UserControl Public Shadows ReadOnly Property Page() As BasePage Get Return CType(MyBase.Page, BasePage) End Get End Property End Class Code (markup): code for index.aspx: Public Class products : Inherits BasePage Code (markup): i need to get the property "FullProduct" from "header.ascx" (type: object "Product") while in the page "/products/index.aspx"...is this not possible since it's dynamically loaded instead of physically placed on the "index.aspx" page? thank you for your help!
What I do is create a property in the MasterPage which loads the data as needed. Then any controls can reference this single property something like this: Article article = (this.Page.Master as IArticleProvider).Article; If you need it to persist from page to page, you should use the Cache object. It provides you advanced caching abilities including priority and timeout features. Hope that helps