在表单的PageLoad事件中,我无法在登录模板中引用服务器端控件。我想念的是什么。因此,当我登录时,我将显示文本框控件,否则将显示诸如“请登录以这样做”之类的文本。

请帮忙 ..

最佳答案

您可以在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控件的所示 View 中的当前控件。在尝试获取文本框之前,您必须测试您是否正在显示登录 View ,或者还可以测试FindControl不返回空引用。

关于asp.net - Loginview控件: how to reference server side controls inside loggedintemplate,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/669551/

10-13 06:38