I’m working on ASP.NET app and in the master page C# code I want to access the login control, so I have the following code:
Login login = new Login();
login = this.Master.FindControl("login") as Login;
But, I get exception ” Object reference not set to an instance of an object” when this line
login = this.Master.FindControl("login") as Login;
is executed.
I can’t see what can be wrong…
Thanks.
If the code mentioned above is in the master page, then try removing the Master portion of the code…
for example
The reason why this would work is because the current master page, is not embedded within another Master page. Therefore, you’ll get an “object not set” error when trying to access the master’s Master page (i.e. this.Master.FindControl())
Just wondering, if this is the case, is there a reason why you can’t access the control by its name?