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

controls collection

hello all,

i am trying to impelement form level security in my vb.net 2003 application.
i have a database table that has the name of the form, subform, userid, and
read,edit,del,add rights (boolean). The subform is a group box or tabpage
that would be visible or enabled (read or edit rights)

my question is:
I have a security class I pass a form object into. When I try to set the
enabled property or visible property on the group box in question, i get a
run-time exception: "Cast from string "grpInventory" to type 'Integer' is
not valid"

Here is the code in my Security class:
MyForm.Controls(subformname).Enabled = True

So how can I access a control on a passed in form, if i cant do it by name?

Thanks a bunch!
george hardy

Jan 16 '06 #1
2 1585
I didn't see a findcontrolbyname, or a getcontrolbyname function listed.
You could create your own though

public notinheritable class formhelperfunctions
public shared function GetControlbyName(Contianer as Control, Name as
string) as control
'any friend or public control will be found within this control

for each ctrl as control in container.controls
if string.compare(ctrl.name,name) = 0 then
return ctrl
end if
next container

end function
end class

Class Form1
private sub TestMe
dim objControl as control
objControl = formhelperfunctions.getcontrolbyname(me,"Textbox1" )
if not objControl is nothing then
..do work here
else
msgbox("there was applying security, an expected control could not be
found.")
me.customstate = customstateenum.securitycouldnotbeset
exit sub
end if
end sub
End Class

"George Hardy" <sp******************@usmedequip.com> wrote in message
news:er****************@TK2MSFTNGP11.phx.gbl...
hello all,

i am trying to impelement form level security in my vb.net 2003
application.
i have a database table that has the name of the form, subform, userid,
and
read,edit,del,add rights (boolean). The subform is a group box or tabpage
that would be visible or enabled (read or edit rights)

my question is:
I have a security class I pass a form object into. When I try to set the
enabled property or visible property on the group box in question, i get a
run-time exception: "Cast from string "grpInventory" to type 'Integer' is
not valid"

Here is the code in my Security class:
MyForm.Controls(subformname).Enabled = True

So how can I access a control on a passed in form, if i cant do it by
name?

Thanks a bunch!
george hardy

Jan 16 '06 #2
thanks! i will give it a try.

george

"AMDRIT" <am****@hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
I didn't see a findcontrolbyname, or a getcontrolbyname function listed.
You could create your own though

public notinheritable class formhelperfunctions
public shared function GetControlbyName(Contianer as Control, Name as
string) as control
'any friend or public control will be found within this control

for each ctrl as control in container.controls
if string.compare(ctrl.name,name) = 0 then
return ctrl
end if
next container

end function
end class

Class Form1
private sub TestMe
dim objControl as control
objControl = formhelperfunctions.getcontrolbyname(me,"Textbox1" )
if not objControl is nothing then
..do work here
else
msgbox("there was applying security, an expected control could not be
found.")
me.customstate = customstateenum.securitycouldnotbeset
exit sub
end if
end sub
End Class

"George Hardy" <sp******************@usmedequip.com> wrote in message
news:er****************@TK2MSFTNGP11.phx.gbl...
hello all,

i am trying to impelement form level security in my vb.net 2003
application.
i have a database table that has the name of the form, subform, userid,
and
read,edit,del,add rights (boolean). The subform is a group box or
tabpage
that would be visible or enabled (read or edit rights)

my question is:
I have a security class I pass a form object into. When I try to set the
enabled property or visible property on the group box in question, i get
a
run-time exception: "Cast from string "grpInventory" to type 'Integer' is
not valid"

Here is the code in my Security class:
MyForm.Controls(subformname).Enabled = True

So how can I access a control on a passed in form, if i cant do it by
name?

Thanks a bunch!
george hardy


Jan 17 '06 #3

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

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
2
by: Das | last post by:
Hi All, Where does asp.net stores the objects declared in the page. I have a method where I want to loop through all the controls(textbox, HtmlInputText) within the page. I want to in which...
9
by: Merlin | last post by:
Hi, My code below doesn't work does anyone have any pointers? All my controls are programically added. Dim i As Int16 For i = 0 To Me.Controls.Count - 1 If Me.Controls(i).Name <>...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
6
by: Peter Zolja | last post by:
Hi, I'm building a webcontrol that contains a dynamic list of other controls. My problem is that when I add or remove an item the synchronization between the ViewState and the Controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
0
by: rn5a | last post by:
Suppose I have the following DataGrid: <asp:DataGrid ID="dgUsers" OnUpdateCommand="UpdateDG" runat="server"> <Columns> <TemplateColumn HeaderText="NAME"> <ItemTemplate> <asp:Label...
3
by: Nunzio | last post by:
I am trying to add specific form controls to a VBA collection, so that I can pass the entire collection to another function, and access the individual controls later. I have tried several...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.