Getting error referencing Hyperlink from code-behind

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Kotuby

    Getting error referencing Hyperlink from code-behind

    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:HyperLin k 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.EventArg s) Handles Me.PreRender
    Dim lnkRefine As HyperLink = FindControl("ln kRefine")

    If Not IsDBNull(lnkRef ine) Then
    If strPassthru = "passthru" Then
    lnkRefine.Navig ateUrl =
    "~/Search/SearchDetail.as px?page=base&se archId=" & strSavedSearchI D
    Else
    lnkRefine.Navig ateUrl = "javascript:his tory.go(-1)"
    End If
    End If

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

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

    lnkRefine.Navig ateUrl = "~/Search/SearchDetail.as px?page=base&se archId=" &
    strSavedSearchI D

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

    Any help would be appreciated... thanks



  • bruce barker

    #2
    Re: Getting error referencing Hyperlink from code-behind

    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)

    John Kotuby wrote:
    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:HyperLin k 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.EventArg s) Handles Me.PreRender
    Dim lnkRefine As HyperLink = FindControl("ln kRefine")
    >
    If Not IsDBNull(lnkRef ine) Then
    If strPassthru = "passthru" Then
    lnkRefine.Navig ateUrl =
    "~/Search/SearchDetail.as px?page=base&se archId=" & strSavedSearchI D
    Else
    lnkRefine.Navig ateUrl = "javascript:his tory.go(-1)"
    End If
    End If
    >
    End Sub
    ------------------------------------------------------
    >
    Since the code gets past the If Not IsDBNull(lnkRef ine) I assume (maybe
    incorrectly) that the control was found and object reference instantiated.
    On the line:
    >
    lnkRefine.Navig ateUrl = "~/Search/SearchDetail.as px?page=base&se archId=" &
    strSavedSearchI D
    >
    I am getting the error:
    Object reference not set to an instance of an object
    >
    Any help would be appreciated... thanks
    >
    >
    >

    Comment

    • John Kotuby

      #3
      Re: Getting error referencing Hyperlink from code-behind

      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.

      "bruce barker" <nospam@nospam. comwrote in message
      news:%2379IeLnj HHA.4516@TK2MSF TNGP03.phx.gbl. ..
      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)
      >
      John Kotuby wrote:
      >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:HyperLi nk 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.EventAr gs) Handles Me.PreRender
      >Dim lnkRefine As HyperLink = FindControl("ln kRefine")
      >>
      >If Not IsDBNull(lnkRef ine) Then
      > If strPassthru = "passthru" Then
      > lnkRefine.Navig ateUrl =
      >"~/Search/SearchDetail.as px?page=base&se archId=" & strSavedSearchI D
      > Else
      > lnkRefine.Navig ateUrl = "javascript:his tory.go(-1)"
      > End If
      >End If
      >>
      >End Sub
      >------------------------------------------------------
      >>
      >Since the code gets past the If Not IsDBNull(lnkRef ine) I assume (maybe
      >incorrectly) that the control was found and object reference
      >instantiated . On the line:
      >>
      >lnkRefine.Navi gateUrl = "~/Search/SearchDetail.as px?page=base&se archId="
      >& strSavedSearchI D
      >>
      >I am getting the error:
      >Object reference not set to an instance of an object
      >>
      >Any help would be appreciated... thanks
      >>
      >>

      Comment

      Working...