11 Replies - 2071 Views - Last Post: 14 April 2011 - 02:21 AM Rate Topic: -----

#1 jammu143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 09

Dropdown menu with session

Posted 08 March 2011 - 03:46 AM

Hello everyone
I am creating a website for my project
Now i want to create a verticle menu with dropdown
the dropdwon item is User CP
now the problem is that i want to show only that perticular items/function to user that is currently loggedin into the system
eg :- If Admin has login so in UserCP dropdown all functions is shows and when user login i don't want to show all the menu items
so is it possible?
if yes so please tell me how?
Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Dropdown menu with session

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,452
  • Joined: 28-April 09

Re: Dropdown menu with session

Posted 08 March 2011 - 05:55 AM

Should be possible. You should be able to use Page.user.identity.name to get the current user. Then you just need to filter for that user in the code you're using to populate the drop down. I have no idea how you're doing that so it's kind of hard to say how to do it. Are you using data objects, sql statements, stored procedures or something else? Would probably help to see some of the code you're using for this. If you're storing your user in Session then just use that instead of the Page.use.identity.name property, but either way seeing the code you're using would help a lot in helping you with your problem.

This post has been edited by Nakor: 08 March 2011 - 06:04 AM

Was This Post Helpful? 1
  • +
  • -

#3 jammu143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 09

Re: Dropdown menu with session

Posted 24 March 2011 - 11:56 PM

View PostNakor, on 08 March 2011 - 05:55 AM, said:

Should be possible. You should be able to use Page.user.identity.name to get the current user. Then you just need to filter for that user in the code you're using to populate the drop down. I have no idea how you're doing that so it's kind of hard to say how to do it. Are you using data objects, sql statements, stored procedures or something else? Would probably help to see some of the code you're using for this. If you're storing your user in Session then just use that instead of the Page.use.identity.name property, but either way seeing the code you're using would help a lot in helping you with your problem.


First i am sorry for late reply and second thanks for giving me such idea but the problem is that currently i haven't coded that menu i had created 3 Master Page of my 3 types of user Admin, Staff, Student and created Vertical menu in Master Page directly but i want Only One Master Page With Horizontal Menu and User CP Drop Down which is originally the vertical menu that are currently in Master Pages. If you want to see code so i can mail you my whole project so you can understand
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,452
  • Joined: 28-April 09

Re: Dropdown menu with session

Posted 25 March 2011 - 03:51 AM

Just post the relevant code here so if someone else has the same problem maybe they'll be helped by this as well. You shouldn't need to post the code for your entire project.
Was This Post Helpful? 0
  • +
  • -

#5 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Dropdown menu with session

Posted 25 March 2011 - 03:34 PM

Well its quite simple , as there is no dropdown.Items[2].Visible = false; property .
there is however a dropdown.Items.Remove("your item name to remove");

The following code will illustrate how to use it

     if (User == Valid)
                {
                    
                    //firts clear the Dropdown
                    ddl.Items.Clear();


                //Populate new items
                    ddl.Items.Add("Logout");
                    ddl.Items.Add("Profile");

                }
                else
                {

                    //If he is not admin the use item.remove();
                    ddl.Items.Remove("The item { name } to remove from dropdownlist");

                    
                }


You will have to modify code to fit your needs but i hope its what you want



Greetings

Marinus

This post has been edited by marinus: 25 March 2011 - 03:35 PM

Was This Post Helpful? 1
  • +
  • -

#6 jammu143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 09

Re: Dropdown menu with session

Posted 14 April 2011 - 01:07 AM

I am using this code for menu with CSS

HTML Code
<div class="menu">
		<ul>
			<li><a href="#" >Home</a></li>
			<li><a href="/news.aspx">What's New?</a></li>
			<li><a href="/faq.aspx">F.A.Q.</a></li>			
			<li><a href="/about.aspx">About Us</a></li>
			<li><a href="/contact.aspx">Contact Us</a></li>
			<li><a href="#">User CP</a>
				<ul>
					<li><a href="#">View Profile</a></li>
					<li><a href="#">Change Password</a></li>
					<li><a href="#">Create User</a></li>
					<li><a href="#">View User</a></li>
					<li><a href="#">Send SMS</a></li>
					<li><a href="#">Send email</a></li>
					<li><a href="#">Post News</a></li>
					<li><a href="#">Logout</a></li>
			   </ul>
		  </li>		  	
		</ul>
	</div>


CSS

.menu{
	border:none;
	border:0px;
	margin:0px;
	padding:0px;
	font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
	font-size:14px;
	font-weight:bold;
	}
.menu ul{
	background:#333333;
	height:35px;
	list-style:none;
	margin:0;
	padding:0;
	}
	.menu li{
		float:left;
		padding:0px;
		}
	.menu li a{
		background:#333333 url("images/seperator.gif") bottom right no-repeat;
		color:#cccccc;
		display:block;
		font-weight:normal;
		line-height:35px;
		margin:0px;
		padding:0px 25px;
		text-align:center;
		text-decoration:none;
		}
		.menu li a:hover, .menu ul li:hover a{
			background: #309bcf url("images/hover.png") bottom center no-repeat;
			color:#FFFFFF;
			text-decoration:none;
			}
	.menu li ul{
		background:#333333;
		display:none;
		height:auto;
		padding:0px;
		margin:0px;
		border:0px;
		position:absolute;
		width:225px;
		z-index:200;
		/*top:1em;
		/*left:0;*/
		}
	.menu li:hover ul{
		display:block;
		
		}
	.menu li li {
		background:url('images/sub_sep.gif') bottom left no-repeat;
		display:block;
		float:none;
		margin:0px;
		padding:0px;
		width:225px;
		}
	.menu li:hover li a{
		background:none;
		
		}
	.menu li ul a{
		display:block;
		height:35px;
		font-size:12px;
		font-style:normal;
		margin:0px;
		padding:0px 10px 0px 15px;
		text-align:left;
		}
		.menu li ul a:hover, .menu li ul li:hover a{
			background:#309bcf url('images/hover_sub.png') center left no-repeat;
			border:0px;
			color:#ffffff;
			text-decoration:none;
			}
	.menu p{
		clear:left;
		}



I want to control User CP i don't want to show all the items from it visible to student like Send SMS and Send email..etc
Images are attached please see the attachment and please give me proper solution

Thanks & Regards
Jaimin

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image
  • Attached Image

This post has been edited by jammu143: 14 April 2011 - 01:11 AM

Was This Post Helpful? 0
  • +
  • -

#7 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Dropdown menu with session

Posted 14 April 2011 - 01:12 AM

Ok you can try something like this

<li runat="server" id="mnuLogout" ><a href="#">Logout</a></li>


Where runat server tag makes the control\menu available for server side processing.

C# code.
EDIT
if(!LoggedIn){
   mnuLogout.Visible = False;

//This will hide logout menu when user not logged in

mnuLogout.Style
//To override style attribute go for 
mnuLogout.Style.Add("background-image", "image1.jpg");

//Changes the image on serverside
}



Once the control is accesable in server side , then use the Control.Style Property to set it

To chage the image use

Control.Style.Add("background-image", "image1.jpg");
Super Cool huh!

This post has been edited by marinus: 14 April 2011 - 01:30 AM

Was This Post Helpful? 1
  • +
  • -

#8 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Dropdown menu with session

Posted 14 April 2011 - 01:30 AM

I edited my post please take another look :)
Was This Post Helpful? 1
  • +
  • -

#9 jammu143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 09

Re: Dropdown menu with session

Posted 14 April 2011 - 01:55 AM

Thanks marinus
i had tried it i had created one another master page and
and without checking any condition i tried to hide menu item Logout by this code
<li runat="server" id="mnuLogout" ><a href="#">Logout</a></li>



Ans in CS file in Page lode event

protected void Page_Load(object sender, EventArgs e)
    {
           mnuLogout.Visible = False;
    }


and add this master page to one test page and when i view it in browser it is showing following error

Compiler Error Message: CS0103: The name 'False' does not exist in the current context
Was This Post Helpful? 0
  • +
  • -

#10 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Dropdown menu with session

Posted 14 April 2011 - 02:06 AM

My error.

False should be false , small caps :)

This post has been edited by marinus: 14 April 2011 - 02:08 AM

Was This Post Helpful? 1
  • +
  • -

#11 jammu143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 09

Re: Dropdown menu with session

Posted 14 April 2011 - 02:18 AM

View Postmarinus, on 14 April 2011 - 02:06 AM, said:

My error.

False should be false , small caps :)

Wolaaaaaaaaa it's 100% Working now thank you so much you don't know how big problem you had solved because of this problem i had created 3 Different master page though problem is that in some pages i have to add 2 master page which is not possible so i am very confused but now i got the solution....yapeeeeeeeee

Thanks again
Was This Post Helpful? 0
  • +
  • -

#12 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Dropdown menu with session

Posted 14 April 2011 - 02:21 AM

That's why im here @ D.I.C , to help you :)

You can use this method for any html tag . Its a tenique that will help you in web developement and took me a year to discovery it ,

Now you know what runat="server" does , it's a very powerful tag.

This post has been edited by marinus: 14 April 2011 - 02:25 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1