[英]update linkbutton text dynamically in asp.net
I am trying to change the text for the link-button dynamically based on if the user is logged in or not. 我试图根据用户是否登录来动态更改链接按钮的文本。 The text should be Log-out if user is logged in and vice versa.
如果用户已登录,则文本应为“注销”,反之亦然。 It is always showing Login.
它始终显示“登录”。 I am not sure what I am doing wrong here.
我不确定我在做什么错。
<p><asp:LinkButton ID="MyLnkButton" runat="server" EnableViewState = "False" onClick="MyLnkButton_Click" Text="" ForeColor="Red"/></p>
code behind 背后的代码
if (!Page.IsPostBack)
{
if (Session["USRID"] != null)
{
lblWLC.Text = (string)Session["USRID"];
MyLnkButton.Text = "Logout";
Bind_GV();
}
else
MyLnkButton.Text = "Login";
}
I would reverse the logic question is do you need to call Bind_GV
regardless of post back.. if so I will depict in my code below 我会反过来逻辑问题是,无论发回什么,您是否都需要调用
Bind_GV
。如果是这样,我将在下面的代码中进行描述
if (Page.IsPostBack && !string.IsNullOrEmpty((string)Session["USRID"]))
{
MyLnkButton.Text = "Login";
}
else
{
lblWLC.Text = (string)Session["USRID"];
MyLnkButton.Text = "Logout";
Bind_GV();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.