查找LoginView控件 [英] Find control in loginview

查看:120
本文介绍了查找LoginView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个loginview一个母版,在一个LoginView我有一个asp登录控制。我也有,是不是在loginview包含一个标签。

I have a masterpage with a loginview, in the loginview i have an asp login control. i also have a label that is NOT contained in a loginview.

如何访问在asp登录控件的用户名文本框控件和显示在标签中的文本。

How do i access the username textbox control in the asp login control and display the text in a label.

请帮帮忙!

这是我的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: A complainant can deactivate his account. A manager and technicians accounts are deactivated and if necessary also reactivated by the administrator. the complainant can reactivate his account at any time.

我需要验证在文本框中输入的首先检查用户名,如果它是一个活跃的用户。如果不是它允许他们重新激活它。如何访问从用户名文本框中的文本。其余的我能想出。

i need to validate the username entered in the textbox to first check if it is an active user. if not it allows them to reactivate it. how do i access the text from the username textbox. the rest i can figure out.

推荐答案

也许你必须检查,如果用户进行身份验证或没有,因为文本框里面的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.anonymoustemplate.aspx\">AnonymousTemplate或者它是一个命名空间的问题( WebControls.Login

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;
}

但通常你会得到通过适当的属性,用户名/密码<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.username.aspx\">UserName/Password登录

修改:您的额外的截图是非常小的,但我看到你得到一个InvalidCastException,所以我对空间问题asumption是正确的。

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.

这篇关于查找LoginView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆