Pregunta

I have a LoginView control in my page, and in my loggedin template, I have a control which I need to refer to on page load. The only thing is, the user isn't always logged in when they visit my page and thus it can't find the control on page load. I have a similar problem with a 'register' button in my master page in a login view controller. I have it set to hide if the page url contains 'register', but as soon as the user logs in and the login template changes, the button is no longer in the control and the page throws an error.

Any advice on how to fix?

¿Fue útil?

Solución

When you call FindControl, check for null before attempting to access its properties:

Control c = FindControl("MyControl");
if (c != null)
{
    c.Visible = false; 
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top