+ Reply to Thread
Results 1 to 5 of 5

Thread: Object reference not set to an instance of an object

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Object reference not set to an instance of an object

    err msg: and yes i did read the sticky
    Code:
     Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    Source Error:
    
    Line 329:
    Line 330:                    Dim lbPageNumber As LinkButton
    Line 331:                    lbPageNumber.Text = x.ToString()
    Line 332:                    lbPageNumber.CommandName = "PageNumber"
    Line 333:                    lbPageNumber.CommandArgument = x
    
    
    Source File: C:\Inetpub\wwwroot\keithdesign\views\projects.aspx.vb    Line: 331
    
    Stack Trace:
    
    [NullReferenceException: Object reference not set to an instance of an object.]
       view_projects.DrawPaging(Int32 pageNumber, Int32 pageCount) in C:\Inetpub\wwwroot\keithdesign\views\projects.aspx.vb:331
       view_projects.Populate_rpProjectList(Params myParams) in C:\Inetpub\wwwroot\keithdesign\views\projects.aspx.vb:83
       view_projects.Page_Load() in C:\Inetpub\wwwroot\keithdesign\views\projects.aspx.vb:26
       System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) +5
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +858603
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
    
    error line in red:
    Code:
    Dim x, y, z, pageEnd, pageStart As Integer
     For x = pageStart To pageEnd
                    If x = pageNumber Then
                        'sb.Append("<strong>[")
                        'sb.Append(x)
                        'sb.Append("]</strong>&nbsp;&nbsp;")
    
                        Dim lbPageNumber As LinkButton
                        lbPageNumber.Text = x
                        lbPageNumber.CommandName = "PageNumber"
                        lbPageNumber.CommandArgument = x
                        lbPageNumber.Visible = True
                        lbPageNumber.Enabled = False
                        lbPageNumber.Font.Bold = True
                        AddHandler lbPageNumber.Command, AddressOf lblPageLinks_OnClick
                        pnlPagelinks.Controls.Add(lbPageNumber)
                    Else
                        'sb.Append("<a href=")
                        'sb.Append(DrawLink(x))
                        'sb.Append(">")
                        'sb.Append(x)
                        'sb.Append("</a>&nbsp;&nbsp;")
    
                        Dim lbPageNumber As LinkButton
                        lbPageNumber.Text = x
                        lbPageNumber.CommandName = "PageNumber"
                        lbPageNumber.CommandArgument = x
                        lbPageNumber.Visible = True
                        AddHandler lbPageNumber.Command, AddressOf lblPageLinks_OnClick
                        pnlPagelinks.Controls.Add(lbPageNumber)
                    End If
                Next
    
    dunno why it's throwing that error? any ideas
    Shem

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I think it's because you don't set the instance of the LinkButton to an actual control on your page, so there's no instance of it.

    It would be:-
    Code:
    Dim lbPageNumber As New LinkButton
    
    Or
    Code:
    Dim lbPageNumber As LinkButton = your_linkbutton_id
    
    Or
    Code:
    Dim lbPageNumber As LinkButton = some_control.FindControl("your_linkbutton_id")
    
    I would guess it should be something like the last one.

  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    i'm trying to add LinkButton Controls to a panel control dynamically?

  4. #4
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Quote Originally Posted by richyrich View Post
    I think it's because you don't set the instance of the LinkButton to an actual control on your page, so there's no instance of it.

    It would be:-
    Code:
    Dim lbPageNumber As New LinkButton
    
    Or
    Code:
    Dim lbPageNumber As LinkButton = your_linkbutton_id
    
    Or
    Code:
    Dim lbPageNumber As LinkButton = some_control.FindControl("your_linkbutton_id")
    
    I would guess it should be something like the last one.
    this one seems to have worked
    Code:
    Dim lbPageNumber As New LinkButton
    
    thanks again for ya help

  5. #5
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    W00T it works, and they are all added to my Panle Control too
    now just to make sure that the events fire off

    Shem

+ Reply to Thread

Similar Threads

  1. VBScript Functions Reference
    By jmurrayhead in forum ASP Development
    Replies: 25
    Last Post: October 21st, 2008, 09:31 AM
  2. Dynamically Reference Worksheet Cell/Range
    By BLaaaaaaaaaarche in forum Microsoft Office
    Replies: 2
    Last Post: June 18th, 2008, 04:59 PM
  3. Object reference not set to an instance of an object
    By jmurrayhead in forum .NET Development
    Replies: 1
    Last Post: May 29th, 2008, 11:16 AM
  4. Object Required?!?!?
    By jarvelous in forum ASP Development
    Replies: 2
    Last Post: March 20th, 2008, 01:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO