0
votes

I've come to a scenario where I need to databind something only if the user is logged in. To do this I am using the LoginView control to display a Login control when they are not logged in and a GridView control when they are logged in. However, when I databind to the GridView object in the LoginView, nothing ever gets displayed. I have been debugging it and I am databinding it to a DataTable that definitely has data in it, however nothing shows up.

Here is some of the code: if (User.Identity.IsAuthenticated) { ((GridView)LoginView1.FindControl("GridView1")).DataSource = dt; ((GridView)LoginView1.FindControl("GridView1")).DataBind(); }

Is there a particular reason that this should not work? Is it bad practice?

1

1 Answers

0
votes

why do you use User.Identity.IsAuthenticated when your GridView is in the LoginView Control? Both things do sort of the same. I think you have a race-condition here.

Use the LoginViewControl in your ASPX-page OR the if/Else statement with the User.Identity.IsAuthenticated in your code behind.