Solved

DataGrid Delete Popup Box asp.net (vb)

Posted on 2004-04-09
4
401 Views
Last Modified: 2012-05-04
SEE HOW DO I MAKE THIS WORK.....
When I click on the "Delete" Button, I am wanting a javascript confirm box to appear.  I want to create this script in the code behind and not in the HTML portion.  Any suggestions for the "onclick" attributes to a datagrid button?

'HERE IS MY DELETE BUTTON in HTML Code
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>


'DATAGRID
 Sub dgLinks_Click(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgLinks.ItemCommand
        If e.CommandName = "Edit" Then
            pnlEdit.Visible = True
           
        ElseIf e.CommandName = "Delete" Then
*******HOW DO I MAKE THIS WORK     ***********************
 
      btn.attributes.Add("onclick", "javascript: return confirm('Are you sure you want to remove this item?');")

***********************************************************************
            Dim objDeleteData As New clDeleteData
            Try
                'Delete News Events
                objDeleteData.DeleteApp(CType(dgLinks.DataKeys(e.Item.ItemIndex), Integer))
                'redirect back to the page
                'Response.Redirect("menu.aspx")
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                objDeleteData = Nothing
            End Try
        End If
    End Sub
0
Comment
Question by:luckyinc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 50 total points
ID: 10792332
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10792344
Goes somethig like this

Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
        Select Case e.Item.ItemType
          Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
            Dim myDeleteButton As Button
            myDeleteButton = e.Item.FindControl("btnDelete")
             myDeleteButton.Attributes.Add("onclick",_
                  "return confirm('Are you sure you want to delete this company?');")  ------

        End Select
    End Sub
0
 

Author Comment

by:luckyinc
ID: 10793108
When I tried the ItemCreated command, it did not prompt for the confirm box
0
 

Author Comment

by:luckyinc
ID: 10793284
Is there a way where I could make it work within my datagrid_click event within this ElseIf statement?

 ElseIf e.CommandName = "Delete" Then

            Dim objDeleteData As New clDeleteData
            Try
                'Delete News Events
                objDeleteData.DeleteApp(CType(dgLinks.DataKeys(e.Item.ItemIndex), Integer))
                'redirect back to the page
                'Response.Redirect("menu.aspx")
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                objDeleteData = Nothing
            End Try
        End If
    End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get statistic's from a competitors website?! 1 125
can I post data from an asp page to php page? 4 60
send email part1 9 39
Validating number not work with decimal 4 23
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question