• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 844
  • Last Modified:

Confirmation message box in delete button click

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)
 Else
           Try
                 Dim delcmd As SqlCommand
                 Dim delcmd1 As SqlCommand
                 delcmd = New SqlCommand("Delete from bg_details where bgnumber='" & bgno.SelectedItem.Text & "'", conmcml)
                conmcml.Open()
                delcmd.ExecuteNonQuery()
                delcmd1.ExecuteNonQuery()
                conmcml.Close()
           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

0
norton127
Asked:
norton127
  • 2
1 Solution
 
havj123Commented:
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.
0
 
norton127Author Commented:
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?
0
 
norton127Author Commented:
hello friends please respond regarding this
0
 
AsishRajCommented:
i assume you are using VB.net 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">
	                                            <Columns>
                                                    <asp:BoundColumn DataField="ShopCode" HeaderText="Shop Code" ReadOnly="True">
                                                    </asp:BoundColumn>
                                                    <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"/>
                                                        <ItemTemplate>
                                                            <asp:linkbutton id="cmdDel" runat="server">Delete</asp:linkbutton>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                </Columns>
                                                <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" />
	                                        </asp:DataGrid>

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now