By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

want to create 4 buttons, call same function onclick but different parameters

P: n/a
Help please.

I have a list of items on my page, alongside each of which i have a
DELETE imagebutton. There can be from 0 to 6 items in the list and they
are placed in a table which cannot be dynamically generated, therefore i
have 6 imagebuttons (for DELETE) and 6 labels (for item name) placed in
the table. There is a string array labelText[6] such that i have

label0.Text=labelText[0];
label1.Text=labelText[1];
etc.

and boolean array buttonvisible[6] such that

button0.Visible=buttonVisible[0];
etc.
I would like each imagebutton to call the same function but somehow pass
a parameter to indicate which item should be deleted.

I could then on postback

1) call the function and delete appropriate item from the list -

labelText[button_no_pressed]="";

and

2) make that delete button invisible

buttonVisible[button_no_pressed]=false;
by using the passed parameter(button_no_pressed=0, button_no_pressed=1
etc)
Can I do this by using onCommand , CommandName and CommandArgument which
i don't really understand yet?
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
OnCommand is usually used for this kind of thing on a DataList or in a grid
where it would do what you suggest, however I dont think you can use that as
you said your grid is not/ can not be dynamicly created.

You might try having each of the buttons individual events calling the same
routine with a parameter.
"tony collier" <me*****@hotmail.com> wrote in message
news:Xn*******************************@140.99.99.1 30...
Help please.

I have a list of items on my page, alongside each of which i have a
DELETE imagebutton. There can be from 0 to 6 items in the list and they
are placed in a table which cannot be dynamically generated, therefore i
have 6 imagebuttons (for DELETE) and 6 labels (for item name) placed in
the table. There is a string array labelText[6] such that i have

label0.Text=labelText[0];
label1.Text=labelText[1];
etc.

and boolean array buttonvisible[6] such that

button0.Visible=buttonVisible[0];
etc.
I would like each imagebutton to call the same function but somehow pass
a parameter to indicate which item should be deleted.

I could then on postback

1) call the function and delete appropriate item from the list -

labelText[button_no_pressed]="";

and

2) make that delete button invisible

buttonVisible[button_no_pressed]=false;
by using the passed parameter(button_no_pressed=0, button_no_pressed=1
etc)
Can I do this by using onCommand , CommandName and CommandArgument which
i don't really understand yet?

Nov 18 '05 #2

P: n/a
"Felbrigg" <so*****@microsoft.com> wrote in
news:O#**************@TK2MSFTNGP11.phx.gbl:
OnCommand is usually used for this kind of thing on a DataList or in a
grid where it would do what you suggest, however I dont think you can
use that as you said your grid is not/ can not be dynamicly created.

You might try having each of the buttons individual events calling the
same routine with a parameter.
"tony collier" <me*****@hotmail.com> wrote in message
news:Xn*******************************@140.99.99.1 30...
Help please.

I have a list of items on my page, alongside each of which i have a
DELETE imagebutton. There can be from 0 to 6 items in the list and
they are placed in a table which cannot be dynamically generated,
therefore i have 6 imagebuttons (for DELETE) and 6 labels (for item
name) placed in the table. There is a string array labelText[6] such
that i have

label0.Text=labelText[0];
label1.Text=labelText[1];
etc.

and boolean array buttonvisible[6] such that

button0.Visible=buttonVisible[0];
etc.
I would like each imagebutton to call the same function but somehow
pass a parameter to indicate which item should be deleted.

I could then on postback

1) call the function and delete appropriate item from the list -

labelText[button_no_pressed]="";

and

2) make that delete button invisible

buttonVisible[button_no_pressed]=false;
by using the passed parameter(button_no_pressed=0,
button_no_pressed=1 etc)
Can I do this by using onCommand , CommandName and CommandArgument
which i don't really understand yet?



that is what i want to do - but how . i can't pass a parameter with
onclick.
Nov 18 '05 #3

P: n/a
tony collier <me*****@hotmail.com> wrote in
news:Xn******************************@140.99.99.13 0:
"Felbrigg" <so*****@microsoft.com> wrote in
news:O#**************@TK2MSFTNGP11.phx.gbl:
OnCommand is usually used for this kind of thing on a DataList or in a
grid where it would do what you suggest, however I dont think you can
use that as you said your grid is not/ can not be dynamicly created.

You might try having each of the buttons individual events calling the
same routine with a parameter.
"tony collier" <me*****@hotmail.com> wrote in message
news:Xn*******************************@140.99.99.1 30...
Help please.

I have a list of items on my page, alongside each of which i have a
DELETE imagebutton. There can be from 0 to 6 items in the list and
they are placed in a table which cannot be dynamically generated,
therefore i have 6 imagebuttons (for DELETE) and 6 labels (for item
name) placed in the table. There is a string array labelText[6] such
that i have

label0.Text=labelText[0];
label1.Text=labelText[1];
etc.

and boolean array buttonvisible[6] such that

button0.Visible=buttonVisible[0];
etc.
I would like each imagebutton to call the same function but somehow
pass a parameter to indicate which item should be deleted.

I could then on postback

1) call the function and delete appropriate item from the list -

labelText[button_no_pressed]="";

and

2) make that delete button invisible

buttonVisible[button_no_pressed]=false;
by using the passed parameter(button_no_pressed=0,
button_no_pressed=1 etc)
Can I do this by using onCommand , CommandName and CommandArgument
which i don't really understand yet?



that is what i want to do - but how . i can't pass a parameter with
onclick.


OK - this works:

void submit ( Object sender, CommandEventArgs e )

{
Response.Write("parameter is "+e.CommandName;
}
.......
<asp:ImageButton onCommand="submit" ImageUrl="whatever.gif"
runat="server" CommandName="0" />

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.