Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
1.23/5 (8 votes)
See more:
I am using a master page to provide links for the login page, the "Home page" for the current user and the "Home page" for administrators.

I am using linkbuttons for this purpose, and I am placing them in the same table cell.

In my master page, I attempt to determine which link should be shown:

try
{
   if(session["user_type"].tostring()=="Admin")
   {
       lbtnadminhomepage.visible=true;
       lbtnuserhomepage.visible=false;
       lbtnlogin.visible=false;
   }
   else if(session["user_type"].tostring()=="User")
   {
       lbtnadminhomepage.visible=false;
       lbtnuserhomepage.visible=true;
       lbtnlogin.visible=false;
   }
   else
   {
       lbtnadminhomepage.visible=false;
       lbtnuserhomepage.visible=false;
       lbtnlogin.visible=true;
   }
}
catch(exception ex)
{
    lbtnadminhomepage.visible=false;
    lbtnuserhomepage.visible=false;
    lbtnlogin.visible=true;
}


However, this code is not working and I do not know why!
I stepped through it in the debugger, and found that when I am getting the login for the Admin home page, the condition

if(session["user_type"].tostring()=="Admin")

is working, but the remaining code inside this condition is not working and it shows only the login linkbutton for all the cases...

What could be wrong?
Posted
Updated 5-Feb-10 10:34am
v3

"i do not want to insult but u always speak rudely....

be nice with the people so that they wud also b nice with you..."

Well, let's recap. Before I replied to this post, you had attacked me elsewhere, 1 voted a ton of my articles, which I am certain you are not smart enough to understand, or actually looked at for any reason bar attacking me, and called me names. I answered your question. Your code is horrible. You should NEVER use hard coded strings to check session variables, it is prone to all sorts of bugs that you will never catch easily. You should use a switch instead of else if to make your code readable. Your question makes no sense b/c you don't tell us what the value in the session is when it doesn't behave as you'd hope. Your question is incomplete and your code shows you have a lot to learn, yet some poor fool who thought that all coders are the same, hired you based on price, and what he will get is unmaintainable, buggy mess. You take these jobs by undercutting developers in the West, and then expect us to do the work for you because you don't buy any books, you don't use google, you sure have never learned to write good code, you're just making it up as you go along. Yet, I keep answering you, despite your abuse.

So, who is being nice ?
 
Share this answer
 
arvinder_aneja wrote:
this code is not working and i do not know why..


Well, it's bloody horrible code. Tell me you're writing it for kicks, I'd fire anyone who was paid to create it.


arvinder_aneja wrote:
is working but the remaing code inside this condition is not working and it shows only the login linkbutton for all the cases...


Have you tried debugging it ? Because it's so poorly designed, perhaps your value is user and not User, or someting like that ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900