473,748 Members | 8,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

running client side script after an <asp:ButtonColu mn> 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:ButtonColu mn ButtonType="Pus hButton" CommandName="De lete" .... 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 3163
"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.Attri butes.Add("oncl ick", "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:ButtonColu mn Text="del" ButtonType="Pus hButton"
CommandName="De lete"></asp:ButtonColum n>

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.W ebControls.Butt onColumn =
CType(e.Item.Fi ndControl("btnD elIDIDID"), ButtonColumn)

TIA,

"Steven Spits" <st**********@s ervico.be.net> wrote in message
news:um******** ******@TK2MSFTN GP12.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.Attri butes.Add("oncl ick", "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:ButtonColu mn Text="del" ButtonType="Pus hButton"
CommandName="De lete"></asp:ButtonColum n>

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.W ebControls.Butt onColumn =
CType(e.Item.Fi ndControl("btnD elIDIDID"), ButtonColumn)


Dim btnDelete As Button = CType(e.Item.Ce lls(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.W ebControls.Butt on = e.Item.Cells(4) .Controls(0)

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

btn.CausesValid ation = 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******** ********@TK2MSF TNGP10.phx.gbl. ..
how would you get a reference to the buttoncolumn since it does not have an
ID attribute

<asp:ButtonColu mn Text="del" ButtonType="Pus hButton"
CommandName="De lete"></asp:ButtonColum n>

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.W ebControls.Butt onColumn =
CType(e.Item.Fi ndControl("btnD elIDIDID"), ButtonColumn)

TIA,





"Steven Spits" <st**********@s ervico.be.net> wrote in message
news:um******** ******@TK2MSFTN GP12.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.Attri butes.Add("oncl ick", "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
1810
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 code provided on the website. Once I have this example running correctly, I will need to use the concept in a more complex project. The code I am using involves an webform and an htc file. The code for ScrollPos.htc (which is located in a folder...
2
2842
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 to it to view additional details about the selected result (a second database query is triggered). I want this second query to pop up in a new window, the way it would if I used "window.open" in javascript. I've added a function in the
6
4668
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 user that Delete has been selected and are they sure to continue. I have already used this Attributes.Add ( cmdDelete.Attributes.Add("onClick", "return confirmDelete();") )
4
2286
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 lower area of the form. on the lower area i have validators for validating input.
4
2014
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 reply make sure your suggestion actually works. like a <asp:button> control have a CausesValidation property that allows it to POST a button command event to the server without causing the page to make validation on form inputs, i need to get the...
4
1314
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 ideas on this I would really appreciate your help. Thanks. -- J. D
7
5271
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 called on the server-side. That's easy to do with normal buttons, etc. as follows... <asp:Button ID="ConfirmBtn" Text="ConfimMe!" OnClientClick="if(!confirm('Are you sure?'))return false;" OnClick="ConfirmBtnClickHandler" Runat="server" /> But...
2
7206
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 ASPX page <asp:DataGrid id="MyGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" runat="server" EnableViewState="True"> <Columns>
0
3841
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 for the first time versus when the form is posted (sent to the server), which allows you to program accordingly. · What are user controls and custom controls? Custom controls: A control authored by a user or a third-party software vendor that...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.