all groups > vb.net controls > november 2005 >
You're in the

vb.net controls

group:

Programmatically Manipulating a Control


Programmatically Manipulating a Control sd
11/2/2005 8:50:12 AM
vb.net controls:
I've created a web control that contains my navigation area. By
default, I set the visibility of some groups of buttons to be false.
When a page calls the navigation control, I want to programmatically
change the visibility for the set of buttons associated with the
calling page from invisible to visible. For example, when the "Add
Data" page calls the navigation, the various Add buttons will be
visible. When the "Search" page calls the navigation, the Add buttons
will not be visible.

I'm adding the navigation to the target pages by reference (which seems
to be working fine). Inside the navigation control (Navigation.ascx), I
have a Web Forms Panel named "AddNewIncidentPanel" that contains the
buttons I want to see (or hide). The aspx page that calls
Navigation.ascx uses a placeholder to handle the insertion of the
navigation area.

In my code-behind page, I've got:
---
Dim NavigationControl As Control = LoadControl("Navigation.ascx")
NavigationHolder.Controls.Add(NavigationControl)
AddNewIncidentPanel.Visible = True
---

When I run this code, I get the following error:
---
System.NullReferenceException: Object reference not set to an instance
of an object.
---

I've tried a number of Intellisense-suggested options and I'm sure I'm
overlooking something really obvious, but I'm stuck.

Where have I gone wrong?

Thanks!

Scott
Re: Programmatically Manipulating a Control Neil Wallace
11/7/2005 12:00:00 AM
[quoted text, click to view]

Isn't this simply that you are referencing a control, rather than setting up
a new one?
Have you tried.....

Dim NavigationControl As New Control
NavigationControl = LoadControl("Navigation.ascx")
NavigationHolder.Controls.Add(NavigationControl)
AddNewIncidentPanel.Visible = True


AddThis Social Bookmark Button