Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Object reference not set to an instance of an object" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 22nd, 2008, 04:21 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default 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
Reply With Quote
Sponsored Links
  #2  
Old July 22nd, 2008, 04:35 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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.
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 22nd, 2008)
  #3  
Old July 22nd, 2008, 04:44 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

i'm trying to add LinkButton Controls to a panel control dynamically?
Reply With Quote
  #4  
Old July 22nd, 2008, 04:47 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #5  
Old July 22nd, 2008, 04:59 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript Functions Reference jmurrayhead ASP Development 25 October 21st, 2008 08:31 AM
Dynamically Reference Worksheet Cell/Range BLaaaaaaaaaarche Microsoft Office 2 June 18th, 2008 03:59 PM
Object reference not set to an instance of an object jmurrayhead .Net Development 1 May 29th, 2008 10:16 AM
[Error] Object Required?!?!? jarvelous ASP Development 2 March 20th, 2008 12:46 PM


All times are GMT -4. The time now is 08:22 PM.



Content Relevant URLs by vBSEO 3.2.0