accessing a web user control in master page

Posted by Jopito under ASP.NET on 1/27/2014 | Points: 10 | Views : 1081 | Status : [Member] | Replies : 2
Hi,i have a web user control called StudentsPanel in my master page.I have palced it under the login view as shown below
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Students">
<ContentTemplate>
<uc1:studentPanel runat="server" ID="students_control" />
</ContentTemplate>
</asp:RoleGroup>

</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>



I need to access the control in my aspx page such that i can disable it on page load.I have tried using the code below but am getting null results.Please someone guide me on this,Below is the code i am using but keeps getting null

LoginView control;

Page page = (Page)this.Page;
MasterPage master = (MasterPage)page.Master;

control= (LoginView)master.FindControl("students_control");

if (control!= null)
{
Label1.Text = "found";
}


Mark as answer if satisfied


Responses

Posted by: vishalneeraj-24503 on: 1/27/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Use below code to access User Control:

Control myCtrl = Master.FindControl("Your User Control Name");


Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jopito on: 1/27/2014 [Member] Starter | Points: 25

Up
0
Down
Have tried that more than 10 times but no luck

Mark as answer if satisfied

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response