Link to home
Create AccountLog in
Avatar of groovbox303
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)
        Try
                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
                         ('hdAnswer');")
                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
                    GrdXWalk.DataBind()
                    UpdatePanel1.Update()
                End If
            Else
                GrdXWalk.DataSource = XWalkODS
                GrdXWalk.PageIndex = e.NewPageIndex
                GrdXWalk.DataBind()
                UpdatePanel1.Update()
            End If
 
        Catch ex As Exception
            'ExceptionManager.Publish(ex)
            Throw
        End Try
    End Sub

Open in new window

SOLUTION
Avatar of 60MXG
60MXG

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.