Tags: articles, findcontrol, loginview, loginviewfindcontrol, method, net, null, online, returning, security, suggested

LoginView.FindControl returning null

On .Net » .Net Security

3,700 words with 1 Comments; publish: Sat, 05 Jan 2008 23:47:00 GMT; (10062.50, « »)

Hello,

I am having problems with the FindControl method of the LoginView. From articles I have read online, it is suggested that I should be able to use FindControl to access controls nested within a LoginView.

In my situation, I have the following markup:

<asp

:LoginViewID="lgBookingEngineByRole"runat="server">

<RoleGroups>

<asp:RoleGroupRoles="hdn-BookingFinancial">

<ContentTemplate>

<asp:LabelID="lblTest"runat="server"/>

</ContentTemplate>

</asp:RoleGroup">

</RoleGroups>

</asp:LoginView>

And the VB.Net code in Page_Load:

Dim

theLabelAs Label =CType(Me.lgBookingEngineByRole.FindControl("lblTest"), Label)

The problem is that theLabel is coming back as Nothing. This is the same problem for any controls I have within this ContentTemplate, including labels and repeaters.

I have tried to find a .FindControl further down the hierarchy, such as lgBookingEngineByRole.<something>.FindControl() but I cannot find anything like this which might be appropriate.

Any ideas as to why I am getting a null reference?

Thankyou,

Ben

All Comments

Leave a comment...

  • 1 Comments
    • I managed to solve my own problem: I was not a member of the role "hdn-BookingFinancial" which I had specified as the required role.

      I added myself to this role and now it works perfectly.

      #1; Sat, 05 Jan 2008 23:48:00 GMT