Access Controls inside Controls

I have a login control (Login1) inside a Login View control (LoginView1).

MembershipUser mbr;

mbr = Membership.GetUser(Login1.UserName);

It can not find control Login1.

 Cheers.

 


Matt

Systems Engineer / ASP.NET Web Developer

mbaughan@raecomputing.com
0
mbaughan
6/11/2008 11:08:45 AM
asp.net.security 27051 articles. 1 followers. Follow

3 Replies
1207 Views

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

You have to use FindControl.

Try creating a local Login control using   LoginView1.FindControl("Login1");


Remember: mark posts that helped you as the answer to aid future readers

Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
0
whatispunk
6/11/2008 2:06:23 PM
MembershipUser mbr; 

LoginView1.FindControl("login1");

mbr = Membership.GetUser(login1.UserName);

The above comes up with - The name 'login1' does not exist in the current context.

Thanks, Matt


Matt

Systems Engineer / ASP.NET Web Developer

mbaughan@raecomputing.com
0
mbaughan
6/11/2008 2:16:11 PM

You have to create a variable to hold the result of your call to FindControl.

Login login = LoginView1.FindControl("login1");

One difficulty with FindControl is that it's not recursive. Meaning if login1 is not a direct child of LoginView1 then it won't find it.

If this is the case try wrapping login1 in an asp:Panel control with ID=loginPanel. Then try:

Login login = loginPanel.FindControl("login1");

Then you can use it like this:

mbr = Membership.GetUser(login.UserName);


Remember: mark posts that helped you as the answer to aid future readers

Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
0
whatispunk
6/11/2008 2:37:20 PM
Reply: