I am working with loginview. There is a gridview inside loginview and I want to Bind it with databse table, but I couldn't access this gridview inside .cs code.
I tried this:
GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
but gridview again hasn't initialized. Note that in a web.config file I set
<authentication mode="Forms"/>
Does someone know the solution of this problem?
The part of code this:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<div class="tab-content" id="mytabcontent">
<div class="tab-pane active" id="new1">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</div>
</LoggedInTemplate>
<AnonymousTemplate>
<asp:HyperLink runat="server" navigationURL = "default.aspx">Login</asp:HyperLink>
</AnonymousTemplate>
</asp:LoginView>
</asp:Content>
You may be getting this error as the user might not be authenticated.
Try
Use Breakpoint and Check whether the the line to access Gridview is called.
UPdate:
To authenticate create a Auth Cookie
// Redirect to Secured page after creating a cookie in login page