troubleshooting Question

Object reference not set to an instance of an object.

Avatar of webdevelop
webdevelop asked on
ASP.NETVisual Basic.NET
8 Comments3 Solutions293 ViewsLast Modified:
In the code behind shown (.aspx page included as well), NextLink.Visible = false (Line 16) is giving the following error:

"System.NullReferenceException: Object reference not set to an instance of an object."

I assume that is occuring b/c the LinkButton is inside of the <HeaderTemplate> on a repeater... Is there any way to keep the LinkButtons inside the HeaderTemplate?  If so, please provide code required.

Public Class PagingCodeBehind
Inherits Page
Protected FirstLink As LinkButton
Protected PreviousLink As LinkButton
Protected NextLink As LinkButton
Protected LastLink As LinkButton
Sub Paging(Optional WhichPage As Integer = 1,Optional 
' If current page is the last page, hide the "next" and "last" navigation links
If CurrentPage = Pages Then
	NextLink.Visible = false
	LastLink.Visible = false
' Otherwise, show the "next" and "last" navigation links and set the page index each will pass when clicked
	NextLink.Visible = true
	LastLink.Visible = true
	NextLink.CommandArgument = CurrentPage + 1
	LastLink.CommandArgument = Pages
End If
End Sub
Index page:
<form runat="server">
<asp:LinkButton runat="server" ID="NextLink" Text="Next &raquo;" onClick="ChangePage" />
<asp:LinkButton runat="server" ID="LastLink" Text="Last &raquo;" onClick="ChangePage" />
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros