PC Review


Reply
 
 
Krunom Ancini
Guest
Posts: n/a
 
      4th Mar 2005
Hi,


I have on my page something about 50 buttons that "user" should use only for
loading some session-variables:

click on the button -> session variables loaded

and i wish that after click, clicked button changes his color and thats no
problem. I use:

Button43.Color=red; ... or something like this... and it works

But here is the problem:

if i after clicking on Button43, wish to click on Button12, my Button 12
also become red (and thats good), but Button43 stays red (and thats bad)!
and i wish that Button43 gets his old/unclicked color!

I want this:
I push one button and this button get his "clicked" color, and all other
buttons should get their "unclicked" color independent (!) on their previous
color/state (clicked or unclicked)...


Thanks in advance,

Krunom.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RG90TmV0SmVyb21l?=
Guest
Posts: n/a
 
      4th Mar 2005
Hi,

earlier we had control array concepts , with that we can solve this easily.
But now in .NET you can try the following way for your need.

Loop through the controls in the page.... and if you find a control is a
button and it is not that one you clicked then make it's collour as unclicked
color. This way you can do it.

foreach (Control control in this.Controls)
{
if (control is Button)
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      4th Mar 2005
Or you could keep the latest button pressed.

You could also have cheboxes or radio buttons allowing to depending on
wether or not the user should be able to load several values at once or not
and have a single button that loads the selected values...

Patrice

--

"DotNetJerome" <reachjerome@_yahoo.com-remove-the-underscore-after@> a écrit
dans le message de
news:35E739FB-CA12-4750-9168-(E-Mail Removed)...
> Hi,
>
> earlier we had control array concepts , with that we can solve this

easily.
> But now in .NET you can try the following way for your need.
>
> Loop through the controls in the page.... and if you find a control is a
> button and it is not that one you clicked then make it's collour as

unclicked
> color. This way you can do it.
>
> foreach (Control control in this.Controls)
> {
> if (control is Button)
> .
> .
> .
> }
>
> The loop must be called in the clcik event of all the buttons.
>
> Cheers,
>
> Jerome. M
>
> "Krunom Ancini" wrote:
>
> > Hi,
> >
> >
> > I have on my page something about 50 buttons that "user" should use only

for
> > loading some session-variables:
> >
> > click on the button -> session variables loaded
> >
> > and i wish that after click, clicked button changes his color and thats

no
> > problem. I use:
> >
> > Button43.Color=red; ... or something like this... and it works
> >
> > But here is the problem:
> >
> > if i after clicking on Button43, wish to click on Button12, my Button 12
> > also become red (and thats good), but Button43 stays red (and thats

bad)!
> > and i wish that Button43 gets his old/unclicked color!
> >
> > I want this:
> > I push one button and this button get his "clicked" color, and all other
> > buttons should get their "unclicked" color independent (!) on their

previous
> > color/state (clicked or unclicked)...
> >
> >
> > Thanks in advance,
> >
> > Krunom.
> >
> >
> >



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Mar 2005
Krunom,

\\\
private void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack)
{
Control frm = this.FindControl("Form1");
foreach (Control ctl in frm.Controls)
if (ctl is Button)
((Button) ctl).BackColor =
System.Drawing.Color.Azure;
}}
///

And then set the buttoncolor in the normal event to its color.

I hope this helps?

Cor


 
Reply With Quote
 
Dennis Myrén
Guest
Posts: n/a
 
      4th Mar 2005
If your buttons name's follow a pattern, you can use an indexer and loop
like this.
Button button = null;
int buttonIndex = 0x1;
while (null != (button = base.FindControl(string.Concat("Button",
buttonIndex ++.ToString())) as Button))
{
button.BackColor = System.Drawing.Color.Azure;
}


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Krunom Ancini" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
>
> I have on my page something about 50 buttons that "user" should use only
> for loading some session-variables:
>
> click on the button -> session variables loaded
>
> and i wish that after click, clicked button changes his color and thats no
> problem. I use:
>
> Button43.Color=red; ... or something like this... and it works
>
> But here is the problem:
>
> if i after clicking on Button43, wish to click on Button12, my Button 12
> also become red (and thats good), but Button43 stays red (and thats bad)!
> and i wish that Button43 gets his old/unclicked color!
>
> I want this:
> I push one button and this button get his "clicked" color, and all other
> buttons should get their "unclicked" color independent (!) on their
> previous color/state (clicked or unclicked)...
>
>
> Thanks in advance,
>
> Krunom.
>



 
Reply With Quote
 
Josh
Guest
Posts: n/a
 
      4th Mar 2005
I would have all of the buttons call the same event!

"DotNetJerome" <reachjerome@_yahoo.com-remove-the-underscore-after@> wrote
in message news:35E739FB-CA12-4750-9168-(E-Mail Removed)...
> Hi,
>
> earlier we had control array concepts , with that we can solve this
> easily.
> But now in .NET you can try the following way for your need.
>
> Loop through the controls in the page.... and if you find a control is a
> button and it is not that one you clicked then make it's collour as
> unclicked
> color. This way you can do it.
>
> foreach (Control control in this.Controls)
> {
> if (control is Button)
> .
> .
> .
> }
>
> The loop must be called in the clcik event of all the buttons.
>
> Cheers,
>
> Jerome. M
>
> "Krunom Ancini" wrote:
>
>> Hi,
>>
>>
>> I have on my page something about 50 buttons that "user" should use only
>> for
>> loading some session-variables:
>>
>> click on the button -> session variables loaded
>>
>> and i wish that after click, clicked button changes his color and thats
>> no
>> problem. I use:
>>
>> Button43.Color=red; ... or something like this... and it works
>>
>> But here is the problem:
>>
>> if i after clicking on Button43, wish to click on Button12, my Button 12
>> also become red (and thats good), but Button43 stays red (and thats bad)!
>> and i wish that Button43 gets his old/unclicked color!
>>
>> I want this:
>> I push one button and this button get his "clicked" color, and all other
>> buttons should get their "unclicked" color independent (!) on their
>> previous
>> color/state (clicked or unclicked)...
>>
>>
>> Thanks in advance,
>>
>> Krunom.
>>
>>
>>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      4th Mar 2005
Dennis Myrén <(E-Mail Removed)> wrote:
> If your buttons name's follow a pattern, you can use an indexer and loop
> like this.
> Button button = null;
> int buttonIndex = 0x1;
> while (null != (button = base.FindControl(string.Concat("Button",
> buttonIndex ++.ToString())) as Button))
> {
> button.BackColor = System.Drawing.Color.Azure;
> }


Or, much better IMO, would be to have an array of buttons:

Button[] buttons = new Button[50];

Then create the buttons dynamically (rather than with the designer),
say from a list of strings. Then it's really easy to add a particular
event handler to all buttons, etc.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Dennis Myrén
Guest
Posts: n/a
 
      7th Mar 2005
Jon,

I agree, that would be the best solution.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Dennis Myrén <(E-Mail Removed)> wrote:
> If your buttons name's follow a pattern, you can use an indexer and loop
> like this.
> Button button = null;
> int buttonIndex = 0x1;
> while (null != (button = base.FindControl(string.Concat("Button",
> buttonIndex ++.ToString())) as Button))
> {
> button.BackColor = System.Drawing.Color.Azure;
> }


Or, much better IMO, would be to have an array of buttons:

Button[] buttons = new Button[50];

Then create the buttons dynamically (rather than with the designer),
say from a list of strings. Then it's really easy to add a particular
event handler to all buttons, etc.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      7th Mar 2005
Dennis,

> I agree, that would be the best solution.
>


Why

Be aware that this is about a webform

Cor


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      7th Mar 2005
Cor Ligthert <(E-Mail Removed)> wrote:
> Dennis,
>
> > I agree, that would be the best solution.


> Why
>
> Be aware that this is about a webform


Because whatever kind of solution it is, dealing with an ordered
collection of objects is almost always easier if that collection is
easily indexed. An array (or list) provides that ability very simply.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
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
Buttons or links in Word like Outlook voting buttons Heidi Microsoft Word Document Management 2 28th Aug 2009 03:12 PM
have toggle buttons but everytime print preview buttons move =?Utf-8?B?VGluU2FuZGh1?= Microsoft Excel Misc 1 11th Oct 2006 02:57 PM
Outlook 2007 - HTML radio buttons, submit buttons, text fields... =?Utf-8?B?bWlndWVsaXRvOTI4?= Microsoft Outlook Discussion 2 13th Sep 2006 08:20 PM
Changing interactive buttons back to buttons in original theme. Chris Microsoft Frontpage 2 23rd Jun 2006 09:42 AM
2 buttons but want enter key in textbox to execute one buttons' click event? Roger Microsoft ASP .NET 1 20th May 2005 10:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 PM.