[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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

Posted on 2014-02-22
Medium Priority
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
                If v_bitContactMade.SelectedItem Is "1" Then
                    vw_pnlYesContact.Visible = True
                    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.

Question by:Steven O'Neill
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
LVL 40
ID: 39879303
What line is triggering the exception?

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.
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.
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!


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
LVL 29

Accepted Solution

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)
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.

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

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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 …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 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