Anton Andersen
Anton Andersen

Reputation: 11

If Session match string

I got a little problem. I got a if statement which says if Session isn't equal 3, then do something, and if that isn't true, then do something else. My problem is just, that it isn't working proberly.

I've already tried: 1)

if (Session["userrank"] != "3")
{
   pnlAdmin.Visible = false;
}
else
{
   pnlAdmin.Visible = true;
}

2)

if (Session["userrank"].ToString() != "3")
{
   pnlAdmin.Visible = false;
}
else
{
   pnlAdmin.Visible = true;
}

3)

if ((string)Session["userrank"] != "3")
{
   pnlAdmin.Visible = false;
}
else
{
   pnlAdmin.Visible = true;
}

4)

if (((string)Session["userrank"]) != "3")
{
   pnlAdmin.Visible = false;
}
else
{
   pnlAdmin.Visible = true;
}

but none of them seems to work. And i have already checked if there's a Session called userrank that is getting the result 3.

sorry for the "stupid" question. I'm kind of new to C# & ASP.net.

Best Regards, Anton

Upvotes: 0

Views: 73

Answers (1)

Jonathan Wood
Jonathan Wood

Reputation: 67295

Your code sets pnlAdmin.Visible = false; if whatever is in Session["userrank"] is not 3.

It sets pnlAdmin.Visible = true; if whatever is in Session["userrank"] is 3.

You said it is 3; therefore, the panel should be visible. And that seems to be what is happening.

Upvotes: 2

Related Questions