G
Guest
Hello,
Here's what I am trying to accomplish:
In my web application users can belong to the following roles; 1) System
User 2) Adming User. If a user is not in any of these roles (means not a
system user), he/she will only be able to view some content, however buttons
like "Edit", "Add", "Save", etc. will be hidden from “not a system userâ€.
So, I have the following if statement all over my code:
If not (User.IsInRole("Admin") or User.IsInRole("System User")) Then
btnSomeButton.Visible = False
What I want to do is to create a control that inherits from
WebControls.Button checks for that condition and hides itself if true. I
added a new class that inherits from WebControls.Button, and override
PreRender Sub:
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If Not (Page.User.IsInRole("Admin") Or Page.User.IsInRole("System
User")) Then Me.Visible = False
End Sub
Now I have the following questions:
1.) Is this the right approach in general to accomplish such requirements?
2.) Is OnPreRender the right place for this code?
3.) How do I place this control in VS.NET Designer?
4.) Do I need to declare Public OnClick Event, so it can be hadeled by the
client to this class or is it inherited
5.) Basically, if anyone who has done similar things, could you steer me in
the right direction; any relevant links, articles, code snippets.
Thank you Guys
Here's what I am trying to accomplish:
In my web application users can belong to the following roles; 1) System
User 2) Adming User. If a user is not in any of these roles (means not a
system user), he/she will only be able to view some content, however buttons
like "Edit", "Add", "Save", etc. will be hidden from “not a system userâ€.
So, I have the following if statement all over my code:
If not (User.IsInRole("Admin") or User.IsInRole("System User")) Then
btnSomeButton.Visible = False
What I want to do is to create a control that inherits from
WebControls.Button checks for that condition and hides itself if true. I
added a new class that inherits from WebControls.Button, and override
PreRender Sub:
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If Not (Page.User.IsInRole("Admin") Or Page.User.IsInRole("System
User")) Then Me.Visible = False
End Sub
Now I have the following questions:
1.) Is this the right approach in general to accomplish such requirements?
2.) Is OnPreRender the right place for this code?
3.) How do I place this control in VS.NET Designer?
4.) Do I need to declare Public OnClick Event, so it can be hadeled by the
client to this class or is it inherited
5.) Basically, if anyone who has done similar things, could you steer me in
the right direction; any relevant links, articles, code snippets.
Thank you Guys