running client side script after an <asp:ButtonColumn> click event

S

Steven Spits

i have a datagrid with a delete button for each row in the grid.
when the delete button is clicked i need to ask the user in a "confirm"
message box if he's sure he wants to delete.

Get a reference to the delete button in the ItemCreated event of your
datagrid, then use:

btnDelete.Attributes.Add("onclick", "return confirm('Delete record?');");

Steven

- - -
 
S

Steven Spits

z. f. said:
how would you get a reference to the buttoncolumn since it does not have an
ID attribute

<asp:ButtonColumn Text="del" ButtonType="PushButton"
CommandName="Delete"></asp:ButtonColumn>

and also the findControl method would not cast to the boundColumn type of
the button - the following line of code will not compile:
Dim btn As System.Web.UI.WebControls.ButtonColumn =
CType(e.Item.FindControl("btnDelIDIDID"), ButtonColumn)

Dim btnDelete As Button = CType(e.Item.Cells(0).Controls(0), Button)

Modify the indexes!

Steven

- - -
 
Z

z. f.

Hi,

i have a datagrid with a delete button for each row in the grid.
when the delete button is clicked i need to ask the user in a "confirm"
message box if he's sure he wants to delete.
the problem is that the
<asp:ButtonColumn ButtonType="PushButton" CommandName="Delete" .... don't
have a property to allow onclick to run client side script . how can this
be,

an i missing here something, cause there must be a way to do this without
implementing the button on my own!

TIA, z.
 
S

Steven Spits

z. f. said:
but somewhere i get the feeling that getting
to the button using it's index (that might change
tomorrow) and having to take care of this index in
order that when it changed the code will not fail is
not the state of the art programming practice,

Use a foreach to loop all cells and all controls in each cell to search for
your button. You could use the CommandName or CommandArgument as a
search-criteria.

Steven

- - -
 
S

Steven Spits

Steven Spits said:
Use a foreach to loop all cells and all controls in each cell to search
for your button. You could use the CommandName or
CommandArgument as a search-criteria.

*or* you could also use a TemplateColumn and put a normal button in it,
which can be given an ID. That way, you could use FindControl().

Steven

- - -
 
Z

z. f.

how would you get a reference to the buttoncolumn since it does not have an
ID attribute

<asp:ButtonColumn Text="del" ButtonType="PushButton"
CommandName="Delete"></asp:ButtonColumn>

and also the findControl method would not cast to the boundColumn type of
the button - the following line of code will not compile:
Dim btn As System.Web.UI.WebControls.ButtonColumn =
CType(e.Item.FindControl("btnDelIDIDID"), ButtonColumn)

TIA,
 
Z

z. f.

the way i did got a reference to the button is:
Dim btn As System.Web.UI.WebControls.Button = e.Item.Cells(4).Controls(0)

btn.Attributes.Add("onclick", "return confirm('Delete record?');")

btn.CausesValidation = False (this doesn't work - how can i do this is another question.)



but somewhere i get the feeling that getting to the button using it's index (that might change tomorrow) and having to take care of this index in order that when it changed the code will not fail is not the state of the art programming practice, i wish someone in this newsgroup will state the microsoft engineers opinion regarding us having to program this way!
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top