473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Ineriting from WebControls.Button

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

Nov 18 '05 #1
2 1000
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
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

Nov 18 '05 #2
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?

"Karl Seguin" wrote:
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
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


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Leif | last post by:
I have 2 HTML buttons and 1 WebControls Button on my page. I have set the 'CausesValidation' attribute of my WebControls button to False in the hope that when a user hits Enter the button will not...
8
by: tatemononai | last post by:
I had a beautiful script that was running, well, just beautifully. But then I decided to take a button that fired an event and place it inside a <asp:table. The event WILL NOT FIRE INSIDE THE...
1
by: Klaus Jensen | last post by:
Hi! This has been annoying me all day, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a...
5
by: csgraham74 | last post by:
Hi guys, I posted regarding this issue the other day but i still dont have an answer to my problem. Basically i have imported asp.net pages from dreamweaver into visual studio. Ive added a...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
1
by: Bruce | last post by:
I use btnSave.Attributes.Add("onclick", "ShowMessage()") to link my web control button to a JavaScript function. It works well until I added a Validation control into the page. After that,...
0
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
2
by: chrisp | last post by:
I have an ASP.NET 2 page with a button that causes a credit card transaction to be authorised. The authorisation procedure may take a few seconds and so I want to prevent the user from clicking the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.