Avatar of groovbox303

asked on 

Gridview Javascript confirm popup in paging

Hi experts, I am stuck on something I couldnt much help for anywhere online, hopefully someone here can help me out with this :) . I have a gridview control in my page that allows bulk editing. If the user is in Edit mode and wants to go to the next page I want to display a confirm pop up or message telling the user the edited changes will be lost if they contine without saving, I have made a javascript function below but its not working. I have a generic list called Edited Rows, if there are any items in there I want to display this message and get the answer from the user and either go to the next page or stop there so the user can hit save changes button the form. I have made a hidden html input called "hdAnswer" and made it a server control by adding runat=server in it. I change its value to check weather the user selected ok or not. The Code behind is below for the Gridview_PageIndexChanging event. Any help would be really appreciated since I am not able to find much on this. Many thanks in advance!
Protected Sub GrdXWalk_PageIndexChanging(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
                If EditedRows.Count > 0 Then
                Dim Sb As New StringBuilder
                Sb.Append("<script language='Javascript'>")
                Sb.Append("function Ask() {")
                Sb.Append("var answer = return confirm('Do you want to 
                          discard changes and Continue?';")
                Sb.Append("var Control = document.getElementById
                Sb.Append("if (answer)")
                Sb.Append("Control.value = 'Yes';")
                Sb.Append("else Control.value = 'No';")
                Sb.Append("} </script>")
                Page.RegisterClientScriptBlock("Testing", Sb.ToString())
                If hdAnswer.value = "Yes" Then
                    GrdXWalk.DataSource = XWalkODS
                    GrdXWalk.PageIndex = e.NewPageIndex
                End If
                GrdXWalk.DataSource = XWalkODS
                GrdXWalk.PageIndex = e.NewPageIndex
            End If
        Catch ex As Exception
        End Try
    End Sub

Open in new window

Editors IDEsWeb Applications

Avatar of undefined
Last Comment

8/22/2022 - Mon