473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3123
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
6
by: RSB | last post by:
Hi Everyone, i am using a ASP: DataGrid control in the page and for each row i have a Delete Button Column. Every thing works fine. But now i want to add a Java script confirmation check for the...
4
by: z. f. | last post by:
Hi, I'm having an aspx page with a server form. i have a grid with a delete button and below the grid, another area with inputs for inserting new values and an "add" button for submiting the...
4
by: z. f. | last post by:
Hi, i stated that this is an advanced question because i have a post from few days ago that i received answers to with suggestions that looked good but did not work, so please if you post a...
4
by: JD | last post by:
Hello Everyone, I am writing a asp.net page using vb.net with a datagrid control. I am trying to detect when a row is clicked on in the grid. And I am not sure how to do this, if anyone has any...
7
by: Alex Maghen | last post by:
I have a DataGrid control with a LinkButton command column that deletes the row. What I want to do is set it up so that there's a client-side Confirm alert BEFORE the actual Delete command gets...
2
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.