Hi,
i am developing a website in asp.net, i want to show/Hide div based on user name.
Example:
If user is logged in and user name is USER_123 show this div else hide this div.
regards
firoz khan
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ganesh Singaravelu26 reputationPosted Apr 5, 2014, 5:56 AM EDT
C# :
if(User_Name == "Ganesh")
{
Div_Ex.Attributes.CssStyle[HtmlTextWriterStyle.Visibility] = "hidden";
}
else
{
Div_Ex.Attributes.CssStyle[HtmlTextWriterStyle.Visibility] = "visible";
}
Use this Code. It will help you.
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 6, 2014, 2:57 AM EDT
C# :
if(UserName == "USER_123")
{
dvAccess.Attributes.add["style"]="display:block;";
}
else
{
dvAccess.Attributes.add["style"]="display:none;";
}
Firoz Khan65 reputationPosted Apr 6, 2014, 3:21 AM EDT
protected void Page_Load(object sender, EventArgs e)
{
if (UserName == "firoz")
{
Button2.Visible = false;
}
else
{
Button2.Visible = true;
}
}
what i need to do now plz......suggest me...
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 6, 2014, 3:28 AM EDT
did you crete the "UserName" property on the page or from some object you want to compare.
if (UserName == "firoz")
{
Button2.Visible = false;
}
else
{
Button2.Visible = true;
}
Ans:
Private string UserName="firoz";
protected void Page_Load(object sender, EventArgs e)
{
if (UserName == "firoz")
{
Button2.Visible = false;
}
else
{
Button2.Visible = true;
}
}
Hope this will help
Brijendra GautamRank #1,900 · 778 reputationPosted Apr 6, 2014, 3:43 AM EDT
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview%28v=vs.110%29.aspx