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

T

tony collier

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?
 
F

Felbrigg

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.
 
T

tony collier

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 said:
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.
 
T

tony collier

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 said:
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" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top