当前位置:  开发笔记 > 后端 > 正文

Loginview控件:如何在loggedintemplate中引用服务器端控件

如何解决《Loginview控件:如何在loggedintemplate中引用服务器端控件》经验,为你挑选了1个好方法。

在表单的PageLoad事件中,我无法在登录模板中引用服务器端控件.我错过了什么 因此,当我登录时,我将显示文本框控件,否则我将显示"请登录做soso ..."之类的文字.

请帮忙 ..



1> Scott Ivey..:

你可以在loginview控件上使用FindControl方法来获取它们......

TextBox t = (TextBox)LoginView2.FindControl("TextBox1");
string s = null;

if (t != null)
{
    // textbox is in the current scope of the LoginView
    s = t.text;
}
else
{
    // the textbox is not in the current scope of the LoginView.
}

但是,这仅适用于当前在LoginView控件的显示视图中的控件.在尝试获取文本框之前,您必须测试是否显示已登录的视图,或者您还可以测试FindControl是否未返回空引用.

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有