Confirmation message box in delete button click

Posted on 2009-02-16
Last Modified: 2013-11-19
I am preparing a web application in visual studio .net. In that i have buttons for insert,update,delete for inserting,updating and deleteing a record. In delete when i clicked the record is deleting directly.I want a confirmation dialogbox to be appeared and if the user clicks ok.then it asks to input user code for deleting the record.If the user code is right then it will give permit to delete a record and give an alert message regarding deletion.if code is wrong then it gives for again input.
i am using scripting code for displaying a message if the user not selected key column from dropdownlist. after he selects key column like empid in employee details the confirmation has to come. I am getting code for the confirmation message but not getting the result of box.Plese help me.
Dim strscript As String

        Dim response As String

        strscript = "<script>"

 If bgno.SelectedIndex = 0 Then

            strscript = strscript & "alert('Please Select BG Number');"

            strscript = strscript & "</script>"

            Page.RegisterStartupScript("clientscript", strscript)



                 Dim delcmd As SqlCommand

                 Dim delcmd1 As SqlCommand

                 delcmd = New SqlCommand("Delete from bg_details where bgnumber='" & bgno.SelectedItem.Text & "'", conmcml)





           Catch ex As Exception

                 lblmessage.Visible = True

                 lblmessage.Text = ex.Message

           End Try

    End If


I got the following------------------------------------------------------

 'strscript = strscript & "response=confirm('Are you Sure to Delete BG');"

            'strscript = strscript & "</script>"

            ' Page.RegisterStartupScript("clientscript", strscript)

            'Dim str As String = response

            ' btndelete.Attributes.Add("onclick", "if(confirm('Are you sure you proceed?')){}else{return false;}")

            btndelete.Attributes.Add("onclick", "confirm('hello ')")

            response = btndelete.Attributes.Keys("onclick").ToString

Open in new window

Question by:norton127
    LVL 6

    Expert Comment

    Open the .aspx page. Just goto the <tr> or <td> where u put the Delete button.

    On delete button onClientClick event write confirm message like this

    <asp:button id="button1"  runat="server" text="Delete" OnClientClick="return confirm('Are you sure?');" />

    thats it.

    Author Comment

    Thank you for your response havj123. I have written that code.The message is appearing.But i want the first message to be validated is if the bgnumber is selected or not. If not selected then give an alert message and after selecting only the record will be deleted with a confirmation message. Is there any other solution for this?

    Author Comment

    hello friends please respond regarding this
    LVL 9

    Accepted Solution

    i assume you are using and are using Datagrid

    'code page
    Sub Delete_Datagrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles Delete_Datagrid.ItemDataBound
            Dim l As LinkButton
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                l = CType(e.Item.Cells(Your Cell Number).FindControl("cmdDel"), LinkButton)
                l.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this record?');")
            End If
        End Sub
    'Designing Page
    <asp:Datagrid runat="server"  AutoGenerateColumns="False" 
    	                                            Id="Delete_Datagrid" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" 
                                                    CellPadding="3" CellSpacing="1" Font-Names="Tahoma" Font-Size="Small" 
                                                    HorizontalAlign="Center" Visible="False">
                                                        <asp:BoundColumn DataField="ShopCode" HeaderText="Shop Code" ReadOnly="True">
                                                        <asp:BoundColumn DataField="ShopName" HeaderText="Shop Name" ReadOnly="True"></asp:BoundColumn>
                                                        <asp:BoundColumn DataField="CompanyCode" HeaderText="Company" ReadOnly="True"></asp:BoundColumn>
                                                        <asp:TemplateColumn HeaderText="Delete">
                                                            <HeaderStyle />
                                                            <ItemStyle HorizontalAlign="Center"/>
                                                                <asp:linkbutton id="cmdDel" runat="server">Delete</asp:linkbutton>
                                                    <HeaderStyle BackColor="#3366CC" Font-Bold="False" Font-Italic="False" 
                                                        Font-Names="Tahoma" Font-Overline="False" Font-Size="Small" 
                                                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                                                        ForeColor="White" />

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now