473,385 Members | 1,379 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,385 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 1753
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.