?
Solved

ASP.NET VB.NET System.NullReferenceException: Object reference not set to an instance of an object

Posted on 2014-02-22
7
Medium Priority
?
1,098 Views
Last Modified: 2014-02-22
Most probably the oldest issue here and there are loads of help but I can't seem to find an answer to my situation so hopefully someone can cast an eye over this and help.

I have a form on a page that when it loads will only show certain panels depending upon the results of the questions being asked. All was working perfectly fine until I dropped this into a LoginView and now the code doesn't work.

I assume this is due to how the controls are referenced now that they are 'hidden' behind the relevant templates but I can't seem to get the panels to reference correctly so hopefully someone can help.

Here is my page:

Code Behind:
The problem I'm having is at:
Dim vw_pnlYesContact As Panel = VolView.FindControl("pnlYesContact")
            Dim v_bitContactMade As RadioButtonList = TryCast(VolView.FindControl("bitContactMade"), RadioButtonList)

            If v_bitContactMade Is Nothing Then
                vw_pnlYesContact.Visible = False
            Else
                If v_bitContactMade.SelectedItem Is "1" Then
                    vw_pnlYesContact.Visible = True
                Else
                    vw_pnlYesContact.Visible = False
                End If
            End If

Open in new window


I'm trying to determine if the radionbuttonlist (bitContactmade) is 1 or 0 - if 1 show the panel and if 0 then don't.

On page load the panel visibility should be false (that's what I believe I'm doing here) but I keep getting a System.NullReferenceException: Object reference not set to an instance of an object error every time and it's driving me mad lol.

I assumed I was checking for this in the code above but obviously my little brain isn't comprehending what it needs to so any advice as always guys is appreciated.

Thanx
0
Comment
Question by:Steven O'Neill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 40
ID: 39879303
What line is triggering the exception?
0
 
LVL 2

Author Comment

by:Steven O'Neill
ID: 39879354
Hi there, the last code snippet above is taken from the code behind and is where the error happens.

I'm attempting to have the panel's visibility altered (so it's shown or not shown) and the first part of the last snippet above when it checks the visible element of the panel I'm getting the null error but I assumed my code was checking this but obviously I'm missing something. In that snippet it's shown as line 5.

Sorry for the vagueness here but typing this on an iPhone isn't easy as I can't capture the code snippets to show you exactly the line causing the problem.
0
 
LVL 40
ID: 39879398
If the FindControl method in line 1 does not find a panel called "pnlYesContact", it will return Nothing and you will get the NullReferenceException.

There does not seem to be a panel by that name in your page.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Steven O'Neill
ID: 39879561
That's what I am assuming myself but the panel is there in my code so I'm confused by that. The page checks if the user is authenticated and if they are then they get what's in the Loggedintemplate area and this panel is in there so I'm confused why I get the error.

As I say, brain is fried with this one lol
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1600 total points
ID: 39879581
The panel control is child of the wizard, try :

Dim vw_pnlYesContact As Panel = TryCast(Me.AC_Submission.FindControl("wizStep1_Contact").FindControl("pnlYesContact"),Panel)
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 400 total points
ID: 39879583
OK, I see it now. Missed if first time.

I am more of a Windows programmer than a Web programmer, but from what I understand
pnlYesContact is defined inside of wizStep1_Contact, so it will not be found when you search in VolView as you do with VolView.FindControl. You need to search for it in wizStep1_Contact.
0
 
LVL 2

Author Closing Comment

by:Steven O'Neill
ID: 39879787
Thanx guys, the code from Paul was really useful as put me very much onto the right direction. Thanx also to James for your assistance...you are correct in what I needed to do but the code showed me exactly how to do this and I've been able to get this sorted.

Never knew it had to be done that way...learn something new everyday lol
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question