473,396 Members | 1,804 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.

ASP.NET equilivant of VB6 control array

I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be convienent if I could refer to a specific control by it's index number, in the same way in which I used a Command Array in VB6. What is the method of assigning and then obtaining a specific unique identified for a control ? Sample code or reference articles would be appreciated.
Thanks,
Jim
Jul 21 '05 #1
10 1755
Use the "sender" argument of your event handler to identify which control
fired the event.
"James McGivney" <ac*****@acura66.com> wrote in message
news:C0**********************************@microsof t.com...
I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be convienent
if I could refer to a specific control by it's index number, in the same way
in which I used a Command Array in VB6. What is the method of assigning and
then obtaining a specific unique identified for a control ? Sample code or
reference articles would be appreciated. Thanks,
Jim

Jul 21 '05 #2
Cast the sender argument to the control type and then access its properties.

There is a control array collection equivalent to the VB6 model, but AFAIK
it only works on windows forms.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"James McGivney" <ac*****@acura66.com> wrote in message
news:C0**********************************@microsof t.com...
I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be convienent
if I could refer to a specific control by it's index number, in the same way
in which I used a Command Array in VB6. What is the method of assigning and
then obtaining a specific unique identified for a control ? Sample code or
reference articles would be appreciated. Thanks,
Jim

Jul 21 '05 #3
Can you elaborate on this control array collection available in a windows
forms project?
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Cast the sender argument to the control type and then access its properties.
There is a control array collection equivalent to the VB6 model, but AFAIK
it only works on windows forms.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"James McGivney" <ac*****@acura66.com> wrote in message
news:C0**********************************@microsof t.com...
I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be

convienent if I could refer to a specific control by it's index number, in the same way in which I used a Command Array in VB6. What is the method of assigning and then obtaining a specific unique identified for a control ? Sample code or reference articles would be appreciated.
Thanks,
Jim


Jul 21 '05 #4
Thanks for your help. I'm almost there
I can retreive the name of the pressed button by
string WhichButton = ((System.Web.UI.WebControls.Button)sender).ID.ToSt ring()
Now, how do I use this information, say to change the BackColor
WhichButton.BackColor = Color.Green; generates an error
What is the syntax to change the BackColor having the name of the control
Thanks
Jim
Jul 21 '05 #5
Don't declare WhichButton as a string, declare it as a button. Then set an
object reference to Sender cast as the button type.

Don't have the C# for you, but here it is in VB.NET

Dim WhichButton as System.Web.UI.WebControls.Button
WhichButton = CType(sender, System.Web.UI.WebControls.Button)
WhichButton.BackColor = Color.Green

Or even more simply (no variable reference, just working directly with
sender):

CType(sender, System.Web.UI.WebControls.Button).BackColor = Color.Green

"James McGivney" <ac*****@acura66.com> wrote in message
news:17**********************************@microsof t.com...
Thanks for your help. I'm almost there.
I can retreive the name of the pressed button by:
string WhichButton = ((System.Web.UI.WebControls.Button)sender).ID.ToSt ring(); Now, how do I use this information, say to change the BackColor ?
WhichButton.BackColor = Color.Green; generates an error.
What is the syntax to change the BackColor having the name of the control.
Thanks,
Jim

Jul 21 '05 #6
I've never used them, but for VB.NET GUI projects in (I believe)
compatibility mode, there are a bunch of framework classes that wrap the
control collection functionality. I don't know how close they are to the VB6
ones.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
Can you elaborate on this control array collection available in a windows
forms project?
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Cast the sender argument to the control type and then access its

properties.

There is a control array collection equivalent to the VB6 model, but AFAIK it only works on windows forms.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"James McGivney" <ac*****@acura66.com> wrote in message
news:C0**********************************@microsof t.com...
I have a project in ASP.NET using C#. I have a large number of Button

Controls and a large number of ImageButton Controls. It would be

convienent
if I could refer to a specific control by it's index number, in the same

way
in which I used a Command Array in VB6. What is the method of assigning

and
then obtaining a specific unique identified for a control ? Sample code

or
reference articles would be appreciated.
Thanks,
Jim



Jul 21 '05 #7
I ask because in .NET you can't create a control array in the VB 6.0 sense
(several controls with the same name identified by an index). In .NET, you
can create a collection of controls, but this is not the same thing.

You can get the same benefits of a control array in .NET by assigning one
event handler to handle all the various controls with the event handlers
"Handles" clause and then you can use a Select statement that looks at the
Sender argument to see which one was responsible for firing the event.
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
I've never used them, but for VB.NET GUI projects in (I believe)
compatibility mode, there are a bunch of framework classes that wrap the
control collection functionality. I don't know how close they are to the VB6 ones.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
Can you elaborate on this control array collection available in a windows
forms project?
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Cast the sender argument to the control type and then access its

properties.

There is a control array collection equivalent to the VB6 model, but AFAIK it only works on windows forms.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"James McGivney" <ac*****@acura66.com> wrote in message
news:C0**********************************@microsof t.com...
> I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be

convienent
if I could refer to a specific control by it's index number, in the

same way
in which I used a Command Array in VB6. What is the method of
assigning and
then obtaining a specific unique identified for a control ? Sample
code or
reference articles would be appreciated.
> Thanks,
> Jim



Jul 21 '05 #8
Thanks for your help. I'll try it in C
Jim
Jul 21 '05 #9
I'd like to ask one more related question. From this thread I have learned how to detect which button was clicked and how to use this information to change the properties of the button. But, suppose I find out the 5th button was pressed, now how to I add an image to my 5th ImageButton. Assume that the clicked button is Button5 and the imageButton I want to change is ImageButton5. How do I get the info for imageButton5 ? VB6's index property would make this simple. How do I accomplish this in C#.net
Thanks for your help
Jim
Jul 21 '05 #10
Public Sub CommonEventHander (sender as object, e as eventargs) Handles
button1.click, button2.click, button3.click
'Let's assume that web form button controls are what this event handler
handles
dim testButton as system.web.ui.button

'It's safe to cast sender as a system.web.ui.button because we know that
this is the only type of control this sub handles
testButton = CType(sender, system.web.ui.button)

'Check some property of the button that will identify it uniquely
'In this case, we'll use its name since all controls must have a unique
name

Select Case testButton.name
Case "btnItem1"
'Now that you know "btnItem1" was clicked, do whatever you need
to

Case "btnItem2"
'Now that you know "btnItem2" was clicked, do whatever you need
to

Case "btnItem3"
'Now that you know "btnItem3" was clicked, do whatever you need
to

End Select

End Sub
"James McGivney" <ac*****@acura66.com> wrote in message
news:BF**********************************@microsof t.com...
I'd like to ask one more related question. From this thread I have learned how to detect which button was clicked and how to use this
information to change the properties of the button. But, suppose I find out
the 5th button was pressed, now how to I add an image to my 5th ImageButton.
Assume that the clicked button is Button5 and the imageButton I want to
change is ImageButton5. How do I get the info for imageButton5 ? VB6's
index property would make this simple. How do I accomplish this in C#.net ? Thanks for your help.
Jim

Jul 21 '05 #11

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

Similar topics

4
by: The Mess | last post by:
I would like to pass a Control array of OptionButtons that I created at run time to a Sub. Say I have Opt(0), Opt(1)......Opt(5) as OptionButtons, is there a way to pass Opt to a function and...
3
by: Mani | last post by:
Hi, can anyone help me on how to create a control array in C++ builder like we create in VB. I have another question regarding controls. I want to clear a group of text boxes in the form on a...
5
by: Jim | last post by:
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be appreciated. Is there a tutorial on string maniputation...
3
by: Mark Broadbent | last post by:
In VB6 (using visual studio) it was possible to create a control array at design time by simply adding the control (e.g. textbox) and renaming it to what would become the first element e.g. ...
14
by: Jim Burns | last post by:
I just started with vb.net and I don't understand why there are no control arrays. what replaced them. I was trying to do drag and drop(What happened with that) and it looked like with no control...
10
by: James McGivney | last post by:
I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be convienent if I could refer to a specific control by it's...
6
by: Rich | last post by:
Hello, I have an application that contains several checkboxes. I originally created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I understand the vb2005 supports control...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.