By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,761 Members | 1,879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,761 IT Pros & Developers. It's quick & easy.

Confirmation on a Delete button contained in a WebControls DataGri

P: n/a
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 btnNewTrainingRoom As
System.Web.UI.WebControls.LinkButton
Protected WithEvents dgTrainingRooms As System.Web.UI.WebControls.DataGrid

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)

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

The above code was tested on the btnNewTrainingRoom 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.Control
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
Share this Question
Share on Google+
3 Replies


P: n/a

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.Item.Cells[0].Controls[0], LinkButton)
deleteButton.Attributes.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*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.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 btnNewTrainingRoom As
System.Web.UI.WebControls.LinkButton
Protected WithEvents dgTrainingRooms As System.Web.UI.WebControls.DataGrid

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)

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

The above code was tested on the btnNewTrainingRoom 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.Control
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

P: n/a
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.Item.Cells[0].Controls[0], LinkButton)
deleteButton.Attributes.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*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.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 btnNewTrainingRoom As
System.Web.UI.WebControls.LinkButton
Protected WithEvents dgTrainingRooms As System.Web.UI.WebControls.DataGrid

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)

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

The above code was tested on the btnNewTrainingRoom 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.Control
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

P: n/a

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*******@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.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.Item.Cells[0].Controls[0], LinkButton)
deleteButton.Attributes.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*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.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 btnNewTrainingRoom As
> System.Web.UI.WebControls.LinkButton
> Protected WithEvents dgTrainingRooms As
> System.Web.UI.WebControls.DataGrid
>
> 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)
>
> btnNewTrainingRoom.Attributes.Add("onclick", "return confirm('Delete
> selected contact?');")
>
> The above code was tested on the btnNewTrainingRoom 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.Control
> 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 discussion thread is closed

Replies have been disabled for this discussion.