Accessing controls within a LoginView in the advanced form.

2 posts, 0 answers
  1. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 01 Nov 2012 Link to this post

    I have a RadScheduler where I use the AdvancedInsertTemplate and AdvancedEditTemplate.

    In the AdvancedForm user control I want to show different controls depending on the logged in user is Administrator or a normal user. So I've added a LoginView like this:

    <asp:Panel runat="server" ID="AdvancedControlsPanel" CssClass="rsAdvMoreControls">                  
    <asp:Panel runat="server">
    <%-- RESOURCE CONTROLS --%> 
    <ul class="rsResourceControls">
    <li>
    <asp:LoginView ID="LoginView1" runat="server">
    <RoleGroups>
    <asp:RoleGroup Roles="Administrator">
    <ContentTemplate>
                                                  
    <!-- Resource controls should follow the convention Res[Resource Name] for ID -->
     <scheduler:ResourceControl runat="server" ID="ResCustomer" Type="Customer" Label="Customer: "
    Skin='<%# Owner.Skin %>' />
                                                              
     <telerik:RadComboBox runat="server" ID="EmployeeComboBox" Label="Employee: " Visible="true"
    Skin="Outlook" Width="300px" CausesValidation="false" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"
    OnClientLoad="employeeClientLoad">
    </telerik:RadComboBox>
                                                  
    </ContentTemplate>
    </asp:RoleGroup>
    <asp:RoleGroup Roles="User">
    <ContentTemplate>
    <asp:Label ID="LabelCustomer" runat="server" Text="CustomerName" />
    </ContentTemplate>
    </asp:RoleGroup>
    </RoleGroups>
    </asp:LoginView>
      
    ...

    When compiling I then get an error saying "ResCustomer does not exist in current context":

    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public object Customer
            {
                get
                {
                    return ResCustomer.Value;
                }
      
                set
                {
                    ResCustomer.Value = value;
                }
            }

    I then try to access the controls within the LoginView, but I can't find them:

    LoginView lv = FindControl("LoginView1") as LoginView;
    RadComboBox employeeComboBox = lv.FindControl("EmployeeComboBox") as RadComboBox;
    Label customerLabel = lv.FindControl("LabelCustomer") as Label;

    But now both the employeeComboBox and the customerLabel are null? The LoginView1 has been found, though.

    And how do I find the ResCustomer?

    On the page where the RadScheduler is I have a similar scenario, and there the controls within the LoginView are found without any problem.

    What am I missing?

    Regards, Jill-Connie Lorentsen

  2. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 06 Nov 2012 Link to this post

    Hello Jill,

    The issue seems like an issue that in LoginView itself that is why I would recommend you to refer to some more appropriate ASP.Net forum where this issue have been discussed like these ones:
    http://forums.asp.net/t/1355110.aspx/1
    http://weblogs.asp.net/sukumarraju/archive/2011/01/31/find-control-with-in-loginview-control.aspx

    Once you are able to find the objects you can replace the instances accordingly in the code behind of the advanced form.

    Hope this will be helpful.


    Greetings,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top