locked
Pagination - Can't populate <mobile:label> in <HeaderTemplate>. Error: Object reference not set to an instance of an object. RRS feed

  • Question

  • User-1155837956 posted
    I having problems with a dynamic header in a mobile web form that is paginated. Paginate is set to true on the form, and the ObjectList that is being populated is set to 10 items per page. Originally the header and navigation (<mobile:Label> and <mobile:Link>) controls appeared above the <mobile:ObjectList>, inside the <mobile:Form>. When the page was first rendered, the header and navigation appeared on the first page. But when the Next link was selected, they were not rendered. An associate suggested that these controls should be placed inside the <HeaderTemplate> to make them appear on every page. That worked on all of the static controls. However, one of the labels (named labCity) kicks out the following when I try to populate it with a value from a session variable, "System.NullReferenceException: Object reference not set to an instance of an object." If at all possible, I would prefer to place the mobile labels and links outside the <HeaderTemplate> if there is a way to ensure that they appear on pages beyond the first. The .aspx is pasted below, followed by the .aspx.vb code. Thanks. [[[ .ASPX ]]] <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <%@ Page Language="vb" AutoEventWireup="false" Codebehind="EventsDMA.aspx.vb" Inherits="ArtistTourDates.EventsDMA" %> <HEAD> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/Mobile/Page"> </HEAD> <body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm"> <mobile:Form id="Form1" runat="server" title="Artist Tour Dates" Paginate="True"> <mobile:ObjectList id="oblEvents" runat="server" CommandStyle-StyleReference="subcommand" LabelStyle-StyleReference="title"> <DeviceSpecific> <Choice Filter="isHTML32" Xmlns="http://schemas.microsoft.com/mobile/html32template"> <HeaderTemplate> <mobile:Label id="labCity" runat="server" Font-Bold="True"></mobile:Label> <mobile:Link id="lnkOptions" runat="server" BreakAfter="False" Font-Size="Small" NavigateUrl="Search.aspx">Search</mobile:Link> <mobile:Label id="Label2" runat="server" BreakAfter="False" Font-Size="Small"> > </mobile:Label> <mobile:Link id="lnkResults" runat="server" BreakAfter="False" Font-Size="Small" NavigateUrl="ResultsDMA.aspx">States</mobile:Link> <mobile:Label id="Label1" runat="server" Font-Size="Small"> > Events</mobile:Label> <mobile:Label id="labNoData" runat="server" Visible="False"></mobile:Label>
    </HeaderTemplate> <ItemTemplate> </ItemTemplate> <FooterTemplate>
    <%# CellDate(DataBinder.Eval(Container, "DataItem.FromDate"), DataBinder.Eval(Container, "DataItem.pk_TourID")) %> <%# DataBinder.Eval(Container, "DataItem.Artist") %> <%# CellCity(DataBinder.Eval(Container, "DataItem.CityState")) %>
    </FooterTemplate> </Choice> <Choice Filter="isWML11" Xmlns="http://schemas.microsoft.com/mobile/html32template"> <HeaderTemplate> <small> </HeaderTemplate> <ItemTemplate> </ItemTemplate> <FooterTemplate>
    <%# CellDate(DataBinder.Eval(Container, "DataItem.FromDate"), DataBinder.Eval(Container, "DataItem.pk_TourID")) %> <%# DataBinder.Eval(Container, "DataItem.Artist") %> <%# CellCity(DataBinder.Eval(Container, "DataItem.CityState")) %>
    </small> </FooterTemplate> </Choice> </DeviceSpecific> </mobile:ObjectList> </mobile:Form> [[[ THE CODE BEHIND ]]] Public Class EventsDMA Inherits System.Web.UI.MobileControls.MobilePage #Region " Web Form Designer Generated Code " Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Check session expiration. Dim clsCommon As New ClassCommon clsCommon.CheckSessionExpiration(Len(Session("LabelToken"))) clsCommon = Nothing If Page.IsPostBack = False Then 'Set the referring page for Event.aspx. Session("ReferringPage") = "EventsDMA.aspx" 'Set dates to pass to FillEvents() Dim DateFrom As String = Date.Now.ToShortDateString Dim DateTo As String Dim Range As Integer = Session("Range") Select Case Range Case 0 : DateTo = "" Case Else : DateTo = Today.AddDays(+Range) End Select Call FillEvents(Session("DmaID"), Session("AssociatedLabelsCSV"), DateFrom, DateTo) 'Write page header. labCity.Text = "Tour Events in " & Session("City") 'The code breaks on this line. End If End Sub 'Page_Load() '------------------------------------------------------------------------------ ' CELL CITY '------------------------------------------------------------------------------ Public Function CellCity( _ ByVal argCityState As String) As String Dim clsCommon As New ClassCommon Return clsCommon.FormatCity(argCityState) End Function 'CellCity() '------------------------------------------------------------------------------ ' CELL DATE '------------------------------------------------------------------------------ Public Function CellDate(ByVal argDate As String, _ ByVal argEventID As String) As String Return "" & argDate & "" End Function 'CellDate() '------------------------------------------------------------------------------ ' FILL EVENTS '------------------------------------------------------------------------------ Public Sub FillEvents(ByVal argDMA As String, _ ByVal argLabelCSV As String, _ ByVal argDateFrom As String, _ ByVal argDateTo As String) Dim ws As New ArtistEventWS.Events Dim ds As ArtistEventWS.dsEventsByDMA ds = ws.EventsByDMA(argDMA, argLabelCSV, argDateFrom, argDateTo) If ds.EventsByDMA.Rows.Count = 0 Then labNoData.Visible = True If argDateTo = "" Then labNoData.Text = "No tour events were found in this DMA." Else labNoData.Text = "No tour events were found in this DMA from " & argDateFrom & " to " & argDateTo & "." End If Else oblEvents.DataSource = ds oblEvents.ItemsPerPage = 10 oblEvents.DataBind() End If End Sub 'FillEvents() End Class
    Thursday, November 4, 2004 4:23 PM

All replies

  • User-1155837956 posted
    I just tried sticking the ObjectList in a panel, and setting the panel as the ControlToPaginate, but that did not work. The page rendered the navigation controls at the top of the first page, but subsequent pages did not display the header and links. This suggestion was per another post on this forum (http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=213269). Great idea, but it didn't work in this instance.
    Thursday, November 4, 2004 4:59 PM