473,399 Members | 2,858 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,399 software developers and data experts.

Preventing controls enable property from changing

Pakmarshal
Hi Everyone,
I m implementing control based security in my application. where i m saving controlname (per form) in database, which are to be restricted.

So far I have implemented the security and restricted control get disabled.Now what i want to do is that i have to prevent that for those controls the "control.Enable" property should not change. how can i restrict that.

I have achieved the functionality by canceling enable=true property in "Invalidated" event of the control. but this is not some generic way. I have to map this event for all controls in all forms :(.

What i really want is that as all my froms are derived from same parent which implements the security. so the parent should some how restrict enable property from changing.

So,HOW CAN I PREVENT CONTROL enable property from changing in their parent class?

Regards
Haroon.
Mar 9 '10 #1
8 1780
tlhintoq
3,525 Expert 2GB
Someplace you are setting a bool that means when the user has permission, right?

myControl.Enabled = mySecurityBool;

If they have permission then mySecurityBool is true and thus enabled is true.
Mar 9 '10 #2
tlhintoq
3,525 Expert 2GB
You may also want to just keep them from running Task Manager.
You can limit the programs a user is allowed to run.

http://support.microsoft.com/kb/323525
Mar 9 '10 #3
Thanks a lot tlhintoq for your respose,
But I think I could not convey my problem properly.
let me try again.

for example a "frmEnroll" (is some enrollment form) has a button "btnOk". The button "btnOK" is not allowed to a user "ABC".

What I have already achieved is when frmEnroll loads "btnOk" for user disabled as desired.

Now the functionality in frmEnroll is such that as soon as user enters some text in a textbox, the btnOK gets enable if the button is allowed to the user (IN MY CASE the button is not allowed for "ABC").

now how can i make sure when the coder writes "btnOk.enable=TRUE" in his code. The buttons gets enable if the user is allowed to use the button but in case the user is restricted like "ABC", the button should not change its enabled property.

In the above example I considered just one buttton but in real senerios there are many and i dont want to implement check for every button on every form. Rather I m looking for the mechanism so that the button.Enable event triggers (before actaully enabling the control) to some parent routine where parents check if the user is authenticated to use the button it allows the button to enable other wise if user is not authenticated the event simply get cancelled so that the button wont be enable for restricted users.

Mostly buttons and menus items are getting restricted in my case.

Thanks and Regards,
Haroon.
Mar 10 '10 #4
phommy
4
you mean the controls' Enabled property is a result of more than one variant, is it?
I'm afraid you need to set the Enabled value every time the input changes, or code want to change enable to true. i don't know any shortcut

or you may change the logic slightly. Allow coder to change enabled property. and when endusers click the button with a input 'ABC', show a alert and return
Mar 10 '10 #5
no no
Its simple
I want enabling event to stop triggering.
so that even if their some some statement like button.Enable= TRUE
even then the event get blocked and wont enable the button.

But I dont want this thing in buttonEnabled_EVENT, where i will be reverting the change.

Thanks and Regards,
Haroon.
Mar 10 '10 #6
tlhintoq
3,525 Expert 2GB
You aren't going to block the events. You can stop thinking along those lines right now.
now how can i make sure when the coder writes "btnOk.enable=TRUE" in his code.
What you can do is write an override for the .Enabled property and write your own method for checking all your security parameters. If they are good, then continue to enable it. If they fail, then don't. But you would have to do that for every control and it seems like a big pain.

How about if you you instead subscribe all the controls to a single .EnabledChanged event handler. That method then validates the entire form enabling and disabling all the controls of the form in accordance with your security rules?
Mar 10 '10 #7
phommy
4
try this: set Enabled=false after it is set to true with an input 'ABC'

Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         Button btn;
  4.         TextBox txt;
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.  
  9.             //a textbox
  10.             txt = new TextBox();
  11.             Controls.Add(txt);
  12.  
  13.             //a button to change Enabled of btn
  14.             Button ctrl = new Button();
  15.             ctrl.Top = 40;
  16.             Controls.Add(ctrl);
  17.             ctrl.Click += new EventHandler(ctrl_Click);
  18.  
  19.             //another button whose enabled is changed
  20.             btn = new Button();
  21.             btn.Top = 80;
  22.             Controls.Add(btn);
  23.             btn.EnabledChanged += new EventHandler(btn_EnabledChanged);
  24.         }
  25.  
  26.         void ctrl_Click(object sender, EventArgs e)
  27.         {
  28.             btn.Enabled ^= true;
  29.         }
  30.  
  31.         void btn_EnabledChanged(object sender, EventArgs e)
  32.         {
  33.             (sender as Button).Enabled &= txt.Text != "ABC";
  34.         }
  35.  
  36.         void b1_Click(object sender, EventArgs e)
  37.         {
  38.             btn.Enabled = !btn.Enabled;
  39.         }
  40.     }
  41.  
Mar 11 '10 #8
:) thanks tlhintoq and phommy for your nice and helpful advices.

Thanks.
Mar 11 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Alphonse Giambrone | last post by:
I have a web form with 2 user controls on it (UC1 and UC2). Each control has a bound datagrid with textboxes in the footer to add a new row. There are also requiredfieldvalidators in each footer....
3
by: DBQueen | last post by:
I have a form with lines of controls. On some of the lines there are 3 controls (call them A,B,C); other lines have only control A. The controls have been numbered sequentially (Q20, Q21....Q76)...
5
by: lorirobn | last post by:
Hello, Is there a fix to the Access 2003 problem that makes the tab controls white? I am confused - I have only seen a couple of posts about this on various websites. Have others figured out a...
5
by: Guy | last post by:
Guys Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time I have written a control by inheriting from the Button control....
6
by: Stu Carter | last post by:
Hi, I have an aspx page where some controls are initially disabled by the code-behind 'Page_Load' event. I want these controls to be dynamically enabled when the user checks a checkbox. ...
4
by: Bogdan Zamfir | last post by:
Hi, I want to enable / disable several controls on a page based on a condition in application. But there are several other controls on the page don't want to enable / disable together with...
1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
7
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable...
1
by: Chattanooga | last post by:
hi all, is there a way to enable all controls in a web form? something like for each control in page.controls control.enabled = true next i tried the one above, but that did not give me...
7
by: RichG | last post by:
I want to lock all controls except the buttons on a form. I sometimes need the form to call lockForms(Me). public sub lockControls(frm as form) for each ctrl as control in frm if...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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 project—planning, coding, testing,...

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.