Saturday, November 21, 2015

.NET Find User Control in a Master Page, or really any control

Solution: Set the control you want to access to public or whatever accessibility is needed for your application. To do this, you will need to go into the designer.cs file (assuming you are using visual studio; if not, you should already know how to do that).

Error: (When using FindControl) An exception of type 'System.NullReferenceException' occurred in XXXXX.dll but was not handled in user code

Better solution: Create a public function within the master page to do the actions needed.

Scenario: I wanted to create a dedicated login page and had a login process in the master page. The need was to hide the master page login for the login page.

Although I have not considered during the design phase, this can also be used to manage the menus.