Find control in loginview

enter image description here I have a main page with loginview, in loginview I have asp login control. I also have a label that is NOT contained in loginview.

How do I access a username text box control in an asp control panel and display the text in a shortcut.

Please, help!

This is my code:

Login lg = (Login)LoginView1.FindControl("Login1"); TextBox tb = (TextBox)lg.FindControl("UserName"); Label2.Text = tb.Text; 

OK, this is what I need to do: the applicant can deactivate his account. The accounts of managers and technicians are deactivated and, if necessary, are also activated by the administrator. the plaintiff can reactivate his account at any time.

I need to check the username entered in the text box to first check if he is an active user. if it does not allow them to reactivate it. how can I access the text from the username text box. I can understand the rest.

+7
source share
1 answer

Perhaps you should check whether the user is authenticated or not, because the TextBox is inside the AnonymousTemplate or is it a problem with the namespace ( WebControls.Login ):

 if (!HttpContext.Current.User.Identity.IsAuthenticated) { Login lg = (WebControls.Login)LoginView1.FindControl("Login1"); TextBox tb = (TextBox)lg.FindControl("UserName"); Label2.Text = tb.Text; } 

But usually you should get UserName / Password using the corresponding UserName / Password Login properties.

Change The added screenshot is very small, but I see that you are getting an InvalidCastException, so my assumption about a problem with the namespace was correct.

+9
source

All Articles