我试图在 LoginView LoggedIn 模板中获取 LoginName 控件,尽管有几种方法,但代码仍然无法工作。
我希望将默认用户名更改为客户名称。我尝试在 LoggedInTemplate 中找到控件,但出现此错误:
'System.Web.UI.ITemplate' does not contain a definition for 'FindControl' and no extension method 'FindControl' accepting a first argument of type 'System.Web.UI.ITemplate' could be found (are you missing a using directive or an assembly reference?
这是代码:
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
Hello, <asp:LoginName ID="LoginName1" runat="server"></asp:LoginName>
<br />
<div style="text-align: right; margin-right: 5px ">
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutPageUrl="~/Home.aspx" Font-Underline="True" />
</div></div>
</LoggedInTemplate>
</asp:LoginView>
后面的代码:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
LoginName loginName = LoginView1.LoggedInTemplate.FindControl("LoginName1") as LoginName;
// LoginName loginName = LoginView1.FindControl("LoginName1") as LoginName;
// loginName.FormatString = fullName;
}