Find control in loginview

后端 未结 1 1434
粉色の甜心
粉色の甜心 2020-12-02 02:08

\"enterI have a masterpage with a loginview, in the loginview i have an asp login control. i a

相关标签:
1条回答
  • 2020-12-02 02:34

    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.

    0 讨论(0)
提交回复
热议问题