在表单的PageLoad事件中,我无法在登录模板中引用服务器端控件.我错过了什么 因此,当我登录时,我将显示文本框控件,否则我将显示"请登录做soso ..."之类的文字.
请帮忙 ..
你可以在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是否未返回空引用.