Find control in loginview

血红的双手。 提交于 2019-11-27 09:43:00

Maybe you must check if the user is authenticated or not, because the TextBox is inside the AnonymousTemplate or it's a Namespace issue(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 normally you would get the UserName/Password via the appropriate properties UserName/Password of the Login.

Edit: Your added screenshot is very small but i see that you are getting an InvalidCastException, so my asumption on the namespace issue was correct.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!