470,624 Members | 2,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,624 developers. It's quick & easy.

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

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.
Nov 18 '05 #1
6 2993
"z. f." wrote
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

- - -

Nov 18 '05 #2
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,

"Steven Spits" <st**********@servico.be.net> wrote in message
news:um**************@TK2MSFTNGP12.phx.gbl...
"z. f." wrote
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

- - -

Nov 18 '05 #3
"z. f." wrote:
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

- - -
Nov 18 '05 #4
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!

"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
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,





"Steven Spits" <st**********@servico.be.net> wrote in message
news:um**************@TK2MSFTNGP12.phx.gbl...
"z. f." wrote
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

- - -


Nov 18 '05 #5
"z. f." wrote:
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

- - -
Nov 18 '05 #6
"Steven Spits" wrote:
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

- - -
Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by GrantS | last post: by
4 posts views Thread by JD | last post: by
reply views Thread by shamirza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.