nonesuch
asked on
How to cache calendar lookup in master page
I have a 2.0 VB .NET web site based on a master page. One element of the master page is a display of upcoming events -- it should show on every page. I have a query to pull this from the database. I don't want to query it every time someone hits every single page. And although I can easily put the code in a regular page, I'm running into issues trying to put it into the master page. What's the best way to handle this? I would like to have some mechanism where perhaps each person only hits the database to refresh calendar data once a day, and want it to be on the master page so I don't have to repeat the code elsewhere.
Please that code within a user control and set the output caching for the usercontrol.
ASKER
I'm offering 500 points here. Can you provide some examples or more information? Can I put that inside a master page section?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, so I've put my calendar lookup and display into a user controll, and called it in my MasterPage.master file.
However, when I attempt to include the OutputCache directive, it complains:
Attribute 'OutputCache' is not a valid attribute of element 'Master'
However, when I attempt to include the OutputCache directive, it complains:
Attribute 'OutputCache' is not a valid attribute of element 'Master'
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<%@ Register TagPrefix="Events" TagName="EventListing" src="EventListing.ascx" %>
<%@ OutputCache Duration="360" VaryByCustom="browser" VaryByParam="none" Shared="true" %> -- error on this line
...
...
<Events:EventListing id="myEvents" runat="server" />
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay. I'm having trouble getting the control to work without throwing errors.
Line 2: Imports System.Data
Line 3:
Line 4: Partial Class EventListing
Line 5: Inherits System.Web.UI.Page
Line 6:
Getting an error on line 4:
C:\Inetpub\wwwroot\Test\Ev entListing .ascx.vb(9 12304) : error BC30311: Value of type 'ASP.eventlisting_ascx' cannot be converted to 'System.Web.UI.UserControl '.
CType(Me,System.Web.UI.Use rControl). AppRelativ eVirtualPa th = "~/EventListing.ascx"
~~
here's the codefile for the control:
Line 2: Imports System.Data
Line 3:
Line 4: Partial Class EventListing
Line 5: Inherits System.Web.UI.Page
Line 6:
Getting an error on line 4:
C:\Inetpub\wwwroot\Test\Ev
CType(Me,System.Web.UI.Use
~~
here's the codefile for the control:
Imports System.Data.SqlClient
Imports System.Data
Partial Class EventListing
Inherits System.Web.UI.Page
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
LoadData()
End If
End Sub
Public Sub LoadData()
' create connection
Dim strConnString As String = System.Configuration.ConfigurationManager.AppSettings("sqlConnectionString")
Dim objConn As New SqlConnection(strConnString)
Dim selString As String
selString = "select cdate as sdate, event from calendar_test"
objConn.Open()
' create command object
Dim sqlCommand As New SqlCommand
sqlCommand.CommandText = "cal_web"
sqlCommand.Connection = objConn
sqlCommand.CommandType = CommandType.StoredProcedure
' create data adapter
Dim objDA As New SqlDataAdapter()
objDA.SelectCommand = sqlCommand
' populate dataset and close connection
Dim objDS As New DataSet()
objDA.Fill(objDS)
objConn.Close()
'specify the datasource and call dataBind
dlCalendarEvents.DataSource = objDS
dlCalendarEvents.DataBind()
End Sub
End Class
Inheritance structure for pages
User Control --> System.Web.UI.UserControl
Page --> System.Web.UI.Page
MasterPage --> System.Web.UI.MasterPage
User Control --> System.Web.UI.UserControl
Page --> System.Web.UI.Page
MasterPage --> System.Web.UI.MasterPage
Partial Class EventListing
Inherits System.Web.UI.UserControl
ASKER
Thanks for the assistance~