Ineriting from WebControls.Button

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Thumbs up here. OnPreRender or Render (typically, I'd use Render, but it
shouldn't matter)...the event will be inherited.

For the designer, right click toolbox, select "Add Remove Item", select
".Net Framework Component" and "browse" to the dll containing the
control..unfortunetly, as far as I know, you can only do it via a DLL, and
not from an actual .cs / .vb file in your project.

Karl
 
Thanks for your reply. So it has to be a seperate project to be added to the
designer? There's no way to have as one of the classes in ASP.NET project?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top