Getting error referencing Hyperlink from code-behind

J

John Kotuby

Hi guys...
I must be going brain dead from working on this project for 80 hours in the
last week. I suppose that's part-time for some coders.. anyway...

I created a simple Hyperlink in a user control:

<asp:HyperLink id="lnkRefine" runat="server" >Refine Search</asp:HyperLink>

In the code behind I am trying to set the NavigateURL depending upon a
condition. I include the entire Sub since it may reveal what I am doing
wrong:
----------------------------------------------
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
Dim lnkRefine As HyperLink = FindControl("lnkRefine")

If Not IsDBNull(lnkRefine) Then
If strPassthru = "passthru" Then
lnkRefine.NavigateUrl =
"~/Search/SearchDetail.aspx?page=base&searchId=" & strSavedSearchID
Else
lnkRefine.NavigateUrl = "javascript:history.go(-1)"
End If
End If

End Sub
------------------------------------------------------

Since the code gets past the If Not IsDBNull(lnkRefine) I assume (maybe
incorrectly) that the control was found and object reference instantiated.
On the line:

lnkRefine.NavigateUrl = "~/Search/SearchDetail.aspx?page=base&searchId=" &
strSavedSearchID

I am getting the error:
Object reference not set to an instance of an object

Any help would be appreciated... thanks
 
B

bruce barker

IsDBNull checks is the passed object is the DBNull object. if pass it a
null, it will return true. IsDBNull should only be used database
datatype classes not general classes.

-- bruce (sqlwork.com)
 
J

John Kotuby

Thanks Bruce...

I'd better not post anymore when I am brain-dead. In fact before the post I
was looking straight at an article that showed the syntax:

If Not (myControl Is Nothing) then ...

I guess I just have to find out why the control is not being found now.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top