473,757 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confirmation on a Delete button contained in a WebControls DataGri

Hello, I am developing a web form that contains some buttons and a data grid
which has as its last column link buttons that will delete the data
associated
with that row. Everything works fine, but users have requested a
confirmation
message pop up so the user can confirm the delete. I can not quite get
this to
work. Here are the facts:

I am working in the Microsoft Development Environment 2003 (Version
7.1.3088) and Microsoft .Net Framework 1.1 (Version 1.1.4322).

I have the following controls on the form
Protected WithEvents btnNewTrainingR oom As
System.Web.UI.W ebControls.Link Button
Protected WithEvents dgTrainingRooms As System.Web.UI.W ebControls.Data Grid

The data grid has four coulumns: first is hidden column, columns 2 and 3
have
linkbuttons denoted as Select and a fourth column with a linkbutton denoted as
a delete (per the property builder screen). On the property builder screen
the
select buttons have button types of linkbutton and a command name of select.
The delete button has a button type of linkbutton and a command name of
delete.

I found a solution for adding a confirmation request on a web site. It
works
like this (note this is not the button where I want this action, I am only
testing)

btnNewTrainingR oom.Attributes. Add("onclick", "return confirm('Delete
selected contact?');")

The above code was tested on the btnNewTrainingR oom button and it does
everything
I am looking for. Now the problem is getting the .Attributes.Add associated
with the
delete buttons in my data grid.

Adding this code will allow me to add the "onclick" attribute to all of the
controls
Dim junk As DataGridItem
Dim junk2 As System.Web.UI.C ontrol
For Each junk In dgTrainingRooms .Items ' Iterate through elements.
junk.Attributes .Add("onclick", "return confirm('Delete selected
contact?');")
Next

The confirmation works great, but for every button in the grid including
the
select buttons (which is not good). I only need to nest the .Attributes.Add
code in an IF/END IF block. My problem is that I can not figure out a general
way to determine when I have "delete" linkbutton as opposed to a "select"
linkbutton based on the properties available at that point in time. I have
spent the last two days researching the data members to figure this out, but
nothing has worked. Hopefully, it is just something I am overlooking.
Nov 18 '05 #1
3 2792

All you need to do is reference each cell control by column with something
like this in the ItemCreated event

' Cells[0] points to the first column, Cells[1] would point
to the second...
' therefore make sure this indexes your relevant delete
button column

LinkButton deleteButton =
DirectCast(e.It em.Cells[0].Controls[0], LinkButton)
deleteButton.At tributes.Add ( "onclick", "return
confirm('Delete selected contact?');

Note that it's not in the Page_Load event, so there's no need to parse
through each control. Asp.Net's doing that already when it's creating the
client side webpage, so you may has well hook into that event.

I've not tried the above, so it may need tweaking, any probs let me know.

Thanks.

Daniel.

"vcornjamb" <vc*******@disc ussions.microso ft.com> wrote in message
news:FE******** *************** ***********@mic rosoft.com...
Hello, I am developing a web form that contains some buttons and a data
grid
which has as its last column link buttons that will delete the data
associated
with that row. Everything works fine, but users have requested a
confirmation
message pop up so the user can confirm the delete. I can not quite get
this to
work. Here are the facts:

I am working in the Microsoft Development Environment 2003 (Version
7.1.3088) and Microsoft .Net Framework 1.1 (Version 1.1.4322).

I have the following controls on the form
Protected WithEvents btnNewTrainingR oom As
System.Web.UI.W ebControls.Link Button
Protected WithEvents dgTrainingRooms As System.Web.UI.W ebControls.Data Grid

The data grid has four coulumns: first is hidden column, columns 2 and 3
have
linkbuttons denoted as Select and a fourth column with a linkbutton
denoted as
a delete (per the property builder screen). On the property builder
screen
the
select buttons have button types of linkbutton and a command name of
select.
The delete button has a button type of linkbutton and a command name of
delete.

I found a solution for adding a confirmation request on a web site. It
works
like this (note this is not the button where I want this action, I am only
testing)

btnNewTrainingR oom.Attributes. Add("onclick", "return confirm('Delete
selected contact?');")

The above code was tested on the btnNewTrainingR oom button and it does
everything
I am looking for. Now the problem is getting the .Attributes.Add
associated
with the
delete buttons in my data grid.

Adding this code will allow me to add the "onclick" attribute to all of
the
controls
Dim junk As DataGridItem
Dim junk2 As System.Web.UI.C ontrol
For Each junk In dgTrainingRooms .Items ' Iterate through elements.
junk.Attributes .Add("onclick", "return confirm('Delete selected
contact?');")
Next

The confirmation works great, but for every button in the grid including
the
select buttons (which is not good). I only need to nest the
.Attributes.Add
code in an IF/END IF block. My problem is that I can not figure out a
general
way to determine when I have "delete" linkbutton as opposed to a "select"
linkbutton based on the properties available at that point in time. I
have
spent the last two days researching the data members to figure this out,
but
nothing has worked. Hopefully, it is just something I am overlooking.

Nov 18 '05 #2
Dan, thanks the code example was helpful. I got it to work. However, when
I run the page in the production environment with a fair number of records,
the page loads very slowly. I placed the code in the ItemCreated event
method for the data grid. It looks like the code is run for every row
created, thus the attribute.add is done multiple times. Is this correct?

Is there a way to add the attribute to the underlying delete linkbutton so
it is only done once? I can't figure out how to access the underlying
linkbutton and not each of the individual instances. Tried to see want was
available during the datagrid's load and init events, but could not figure
out a workable solution.

Thanks for your help.

"Dan Bass" wrote:

All you need to do is reference each cell control by column with something
like this in the ItemCreated event

' Cells[0] points to the first column, Cells[1] would point
to the second...
' therefore make sure this indexes your relevant delete
button column

LinkButton deleteButton =
DirectCast(e.It em.Cells[0].Controls[0], LinkButton)
deleteButton.At tributes.Add ( "onclick", "return
confirm('Delete selected contact?');

Note that it's not in the Page_Load event, so there's no need to parse
through each control. Asp.Net's doing that already when it's creating the
client side webpage, so you may has well hook into that event.

I've not tried the above, so it may need tweaking, any probs let me know.

Thanks.

Daniel.

"vcornjamb" <vc*******@disc ussions.microso ft.com> wrote in message
news:FE******** *************** ***********@mic rosoft.com...
Hello, I am developing a web form that contains some buttons and a data
grid
which has as its last column link buttons that will delete the data
associated
with that row. Everything works fine, but users have requested a
confirmation
message pop up so the user can confirm the delete. I can not quite get
this to
work. Here are the facts:

I am working in the Microsoft Development Environment 2003 (Version
7.1.3088) and Microsoft .Net Framework 1.1 (Version 1.1.4322).

I have the following controls on the form
Protected WithEvents btnNewTrainingR oom As
System.Web.UI.W ebControls.Link Button
Protected WithEvents dgTrainingRooms As System.Web.UI.W ebControls.Data Grid

The data grid has four coulumns: first is hidden column, columns 2 and 3
have
linkbuttons denoted as Select and a fourth column with a linkbutton
denoted as
a delete (per the property builder screen). On the property builder
screen
the
select buttons have button types of linkbutton and a command name of
select.
The delete button has a button type of linkbutton and a command name of
delete.

I found a solution for adding a confirmation request on a web site. It
works
like this (note this is not the button where I want this action, I am only
testing)

btnNewTrainingR oom.Attributes. Add("onclick", "return confirm('Delete
selected contact?');")

The above code was tested on the btnNewTrainingR oom button and it does
everything
I am looking for. Now the problem is getting the .Attributes.Add
associated
with the
delete buttons in my data grid.

Adding this code will allow me to add the "onclick" attribute to all of
the
controls
Dim junk As DataGridItem
Dim junk2 As System.Web.UI.C ontrol
For Each junk In dgTrainingRooms .Items ' Iterate through elements.
junk.Attributes .Add("onclick", "return confirm('Delete selected
contact?');")
Next

The confirmation works great, but for every button in the grid including
the
select buttons (which is not good). I only need to nest the
.Attributes.Add
code in an IF/END IF block. My problem is that I can not figure out a
general
way to determine when I have "delete" linkbutton as opposed to a "select"
linkbutton based on the properties available at that point in time. I
have
spent the last two days researching the data members to figure this out,
but
nothing has worked. Hopefully, it is just something I am overlooking.


Nov 18 '05 #3

When the data grid control is rendered to a client, it is simply an HTML
table with rows and columns... Now in the case that you have a control (as
with your delete button), then the file that the client browser actually
views will contain as many "buttons" as there are rows. Because of this, you
need to add the attribute to every control in every row.

If it's taking a long time, consider using paging, then manipulating the
data source in such a way as to return the data set of the current "page".
For example, if page 5 contains rows 50-59, then have the data set that is
bound to the datagrid simply contain these ten records. This should speed
things up considerably.

Thanks.
"vcornjamb" <vc*******@disc ussions.microso ft.com> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
Dan, thanks the code example was helpful. I got it to work. However,
when
I run the page in the production environment with a fair number of
records,
the page loads very slowly. I placed the code in the ItemCreated event
method for the data grid. It looks like the code is run for every row
created, thus the attribute.add is done multiple times. Is this correct?

Is there a way to add the attribute to the underlying delete linkbutton
so
it is only done once? I can't figure out how to access the underlying
linkbutton and not each of the individual instances. Tried to see want
was
available during the datagrid's load and init events, but could not figure
out a workable solution.

Thanks for your help.

"Dan Bass" wrote:

All you need to do is reference each cell control by column with
something
like this in the ItemCreated event

' Cells[0] points to the first column, Cells[1] would
point
to the second...
' therefore make sure this indexes your relevant delete
button column

LinkButton deleteButton =
DirectCast(e.It em.Cells[0].Controls[0], LinkButton)
deleteButton.At tributes.Add ( "onclick", "return
confirm('Delete selected contact?');

Note that it's not in the Page_Load event, so there's no need to parse
through each control. Asp.Net's doing that already when it's creating the
client side webpage, so you may has well hook into that event.

I've not tried the above, so it may need tweaking, any probs let me know.

Thanks.

Daniel.

"vcornjamb" <vc*******@disc ussions.microso ft.com> wrote in message
news:FE******** *************** ***********@mic rosoft.com...
> Hello, I am developing a web form that contains some buttons and a
> data
> grid
> which has as its last column link buttons that will delete the data
> associated
> with that row. Everything works fine, but users have requested a
> confirmation
> message pop up so the user can confirm the delete. I can not quite get
> this to
> work. Here are the facts:
>
> I am working in the Microsoft Development Environment 2003 (Version
> 7.1.3088) and Microsoft .Net Framework 1.1 (Version 1.1.4322).
>
> I have the following controls on the form
> Protected WithEvents btnNewTrainingR oom As
> System.Web.UI.W ebControls.Link Button
> Protected WithEvents dgTrainingRooms As
> System.Web.UI.W ebControls.Data Grid
>
> The data grid has four coulumns: first is hidden column, columns 2 and
> 3
> have
> linkbuttons denoted as Select and a fourth column with a linkbutton
> denoted as
> a delete (per the property builder screen). On the property builder
> screen
> the
> select buttons have button types of linkbutton and a command name of
> select.
> The delete button has a button type of linkbutton and a command name of
> delete.
>
> I found a solution for adding a confirmation request on a web site.
> It
> works
> like this (note this is not the button where I want this action, I am
> only
> testing)
>
> btnNewTrainingR oom.Attributes. Add("onclick", "return confirm('Delete
> selected contact?');")
>
> The above code was tested on the btnNewTrainingR oom button and it does
> everything
> I am looking for. Now the problem is getting the .Attributes.Add
> associated
> with the
> delete buttons in my data grid.
>
> Adding this code will allow me to add the "onclick" attribute to all of
> the
> controls
> Dim junk As DataGridItem
> Dim junk2 As System.Web.UI.C ontrol
> For Each junk In dgTrainingRooms .Items ' Iterate through elements.
> junk.Attributes .Add("onclick", "return confirm('Delete selected
> contact?');")
> Next
>
> The confirmation works great, but for every button in the grid
> including
> the
> select buttons (which is not good). I only need to nest the
> .Attributes.Add
> code in an IF/END IF block. My problem is that I can not figure out a
> general
> way to determine when I have "delete" linkbutton as opposed to a
> "select"
> linkbutton based on the properties available at that point in time. I
> have
> spent the last two days researching the data members to figure this
> out,
> but
> nothing has worked. Hopefully, it is just something I am overlooking.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1852
by: Griff | last post by:
Hi, I have a button column placed on a datagrid at design time that is captioned "Delete". When the user clicks the button, I want to display a confirmation message, that they want to delete that record in the grid. I've pasted my code below. I'm not getting an error, but the code is being ignored. Private Sub dgrdNote_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
0
446
by: Ron Clarke | last post by:
I have a small web app that displays data from a SQL Server database. Using a DataGrid control on a page, the user can delete a row from the database. This works fine. But I want to prompt the user for confirmation ("Are you sure...") before deleting the record. How can I do this from the ASP.NET code? Since the C# code is server-side, is there a way to display a Yes/No type of message box and only take action if the users clicks the "Yes"...
6
3415
by: Dave | last post by:
Hello. I want to prompt user for some action with Yes/No message, I know some tricks in JavaScript, but I need to handle the user answer at server side. Exactly I want to prompt user for confirmation on delete action of some data in my application. How can I do this?
6
4638
by: JenHu | last post by:
Hi experts, I want to add a delete button in my datagrid, and before it deletes from database, I want to have a confirm dialog box for this deletion. I am entry level to the vb.net, and don't know java or c#. The problem is, when I tested the program, there is no pop-up confirmation box for the deletion, can you show me what' wrong with this code? Thank you.
4
3031
by: DrData | last post by:
I'm working on an ASP.Net application written in C#. On one page, there are several datagrid controls used to display, edit and delete detail records relating to the master record also displayed on that page. Each row in each datagrid includes a Delete button (added at runtime by the code-behind page as a ButtonColumn) and an Edit button (added at runtime by the code-behind page as an EditCommandColumn). What is the quickest, easiest and...
5
1942
by: Samy | last post by:
Hi There, I have a label in a datagrid which I make it a input type = radio in ItemDataBound so that radio buttons are shown in the datagrid. This is how I have it... ASPX... <asp:Label ID="_selectedRBtn" Runat="server"></asp:Label> ASPX.CS
5
6703
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious missing here, but after 2 days I am ready to explode ! Please help. To create the Delete button I selected the grid in design view, clicked the "Columns" property and added the Delete button in the
2
1971
by: simon_eyer | last post by:
Hi, I use a datagrid with a delete command. I create a validation on the delete command and i have a problem: the confirmation message is supposes to appear each time I do this command but it appear just sometimes. Is anyone can tell me how to get this message everytime I use this command ? thanks this is my code in the aspx.vb : Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As...
1
1164
vivek kushwaha
by: vivek kushwaha | last post by:
Hi, i have codes like this. code behind page Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandName = "changestatus" Then clsMaster.ExecuteQry("update CaseMaster set Cancel = 'N', CanceledBy = '', CancelReason='', Reason1='', Notes='' where caseid=" & e.Item.Cells(1).Text & "") ...
0
9297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
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
7285
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
6556
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
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
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
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.