PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

ASP.NET equilivant of VB6 control array

 
 
=?Utf-8?B?SmFtZXMgTWNHaXZuZXk=?=
Guest
Posts: n/a
 
      11th Feb 2004
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
 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      11th Feb 2004
Use the "sender" argument of your event handler to identify which control
fired the event.


"James McGivney" <(E-Mail Removed)> wrote in message
news:C015B154-40E1-436C-AF52-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Klaus H. Probst
Guest
Posts: n/a
 
      11th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:C015B154-40E1-436C-AF52-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11th Feb 2004
Can you elaborate on this control array collection available in a windows
forms project?


"Klaus H. Probst" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:C015B154-40E1-436C-AF52-(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
=?Utf-8?B?SmFtZXMgTWNHaXZuZXk=?=
Guest
Posts: n/a
 
      12th Feb 2004
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.ToString()
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
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      12th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:1700AC59-2A1F-4C7D-893D-(E-Mail Removed)...
> 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.ToString();
> 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



 
Reply With Quote
 
Klaus H. Probst
Guest
Posts: n/a
 
      12th Feb 2004
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-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can you elaborate on this control array collection available in a windows
> forms project?
>
>
> "Klaus H. Probst" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:C015B154-40E1-436C-AF52-(E-Mail Removed)...
> > > 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

> >
> >

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      12th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Can you elaborate on this control array collection available in a

windows
> > forms project?
> >
> >
> > "Klaus H. Probst" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:C015B154-40E1-436C-AF52-(E-Mail Removed)...
> > > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
=?Utf-8?B?SmFtZXMgTWNHaXZuZXk=?=
Guest
Posts: n/a
 
      12th Feb 2004
Thanks for your help. I'll try it in C
Jim
 
Reply With Quote
 
=?Utf-8?B?SmFtZXMgTWNHaXZuZXk=?=
Guest
Posts: n/a
 
      13th Feb 2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Old Outlook favorites folder saving attachment - 2003 equilivant noelh Microsoft Outlook Discussion 1 11th Apr 2008 04:26 PM
Asp.Net Equilivant of Me.Name Larry Rebich Microsoft Dot NET 1 17th Dec 2006 07:23 PM
Using control array run time with different control names AB Microsoft VB .NET 4 18th Jan 2006 02:22 PM
Dynamic control array loading, can't unload control/replace with o =?Utf-8?B?Y2luZHk=?= Microsoft ASP .NET 2 8th Jun 2005 04:54 AM
C# equilivant of instr() =?Utf-8?B?Smlt?= Microsoft Dot NET 5 9th Feb 2004 11:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:31 AM.