webdevelop
asked on
Object reference not set to an instance of an object.
In the code behind shown (.aspx page included as well), NextLink.Visible = false (Line 16) is giving the following error:
"System.NullReferenceExcep tion: 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.
Thanks!
"System.NullReferenceExcep
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.
Thanks!
Public Class PagingCodeBehind
Inherits Page
...Edited...
Protected FirstLink As LinkButton
Protected PreviousLink As LinkButton
Protected NextLink As LinkButton
Protected LastLink As LinkButton
...Edited...
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
Else
NextLink.Visible = true
LastLink.Visible = true
NextLink.CommandArgument = CurrentPage + 1
LastLink.CommandArgument = Pages
End If
...Edited...
End Sub
=======================================
Index page:
<form runat="server">
<asp:Repeater
ID="myRepeater"
Runat="server"
OnItemCreated="myRepeater_ItemCreated">
<HeaderTemplate>
...Edited...
<asp:LinkButton runat="server" ID="NextLink" Text="Next »" onClick="ChangePage" />
<asp:LinkButton runat="server" ID="LastLink" Text="Last »" onClick="ChangePage" />
...Edited...
</HeaderTemplate>
<ItemTemplate>
...Edited...
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@graye:
So line 8 isn't doing that? Sorry, those are the only lines that reference NextLink and it worked perfectly before I tried to move the code inside of the headertemplate for UI reasons.
@TMarkham1:
The headertemplate/footertempl ate regions don't repeat, just the itemtemplate region.
I appreciate any further help!
So line 8 isn't doing that? Sorry, those are the only lines that reference NextLink and it worked perfectly before I tried to move the code inside of the headertemplate for UI reasons.
@TMarkham1:
The headertemplate/footertempl
I appreciate any further help!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The solution for me was to take the buttons out of the headertemplate, and set the default visibility on each tag I needed control over. Then, in the code behind I updated code to control visibility on each tag.
As far as I can tell, it can't be done inside the headertemplate.
As far as I can tell, it can't be done inside the headertemplate.
>>>As far as I can tell, it can't be done inside the headertemplate.
As I said in my last comment.
As I said in my last comment.
ASKER
...
Also, I've run into issues using the Visible property sometimes (it actually causes the object not to be rendered in HTML at all). Most of the time, I just apply the "display = hidden" style instead. That way, the item still gets rendered and it is available for client side access if need be later... it's just hidden.