Can someone give me a hint on how it works?
I'm working on a project and specific forms are only allowed to admins.
For example there are forms 1, 2 and 3. forms 1 and 2 is only allowed to admins. Guest is logged in, and the button that redirects to forms 1 and 2 should be disabled when users other than admin is logged in.

Thanks

okay, there are quite a few ways to go about this, i would suggest the below one,
1. you should have a placeholder for saving the list of users, either a DB or an XML, add a column to the users table, say 'IsAdmin' and to this you can set 1 or 0 or Yes or No. (Hope this is already being followed).
2. Retrieve the 'IsAdmin' value and for simplicity you can use an if else statement,

btn.Visible = false; // keep this global.
if(IsAdmin)
btn.Visible = true;
else
btn.Visible = false;

This should solve your problem i suppose.

I was able to do the code before seeing this post and it looks similar to yours. Thank you! Its working now.

I should not even disable the buttons.
Don't even show them if the user is not an admin.

commented: Yup. +13

There a two lines of code you could use Button.Enabled = false or Button.Visible = false

Enabled leaves the button on the screen, but it's grayed out and none of its events will fire. Visible on the other hand makes it disappear so you don't see it.

Either way, place whatever one you want in an 'if' statement that checks the admin flag you have set up and Bobs your uncle

Typically I use the Enabled property only when I want to visually show the user that there is a button to click, but something on the page/form isnt complete/error so until that is corrected, the submit button is not re-enabled.

I use Visible in a scenario like the one the OP is describing. Either show the button or not depending on roles, rights, etc..

Please mark this thread as solved if you have achieved a solution through our posts.
thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.