DebHanleyRI
Programmer
I am a newbie...
I have a datagrid in asp.net where our users record the number of steps they have walked since last week - this works great - however - I have been asked to add a confirm button that will basically say "Are you certain you want to post xxx steps today" after the user clicks update.
Is there a way to add a messagebox to a webpage(with yes and no buttons) that will only execute the code if the user says yes?
Here is the code for my datagrid update:
Sub dgWalkers_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim strName As String
strName = LCase(Session("UserName"))
Dim strCoach As String
strCoach = Session("strCoach")
Dim dblSteps As Double
dblSteps = "0"
'check steps for numeric value
If IsNumeric(CType(e.Item.Cells(5).Controls(0), TextBox).Text) Then
Dim sErr As String, spath1
Dim WalkerID As String = e.Item.Cells(0).Text
Dim dblTotalSteps As Double = e.Item.Cells(1).Text
Dim dblTotalDays As Double = e.Item.Cells(2).Text
Dim dblTotalMiles As Double = e.Item.Cells(3).Text
Dim dtLastReported As Date = e.Item.Cells(4).Text
Dim dblSteps2 As Double = CType(e.Item.Cells(5).Controls(0), TextBox).Text
dblSteps = dblSteps2
'Dim strActive As TextBox = e.Item.Cells(6).Controls(0)
Dim stractive As String = DirectCast(e.Item.Cells(6).FindControl("txtActive"), TextBox).Text
'Dim stractive As String = e.Item.Cells(6).ID("txtactive")
' days Out - hidden column
Dim intDaysOut As Integer = e.Item.Cells(8).Text
' prevent blanks or anything other than Y or N
stractive = UCase(Trim(stractive))
If stractive = "" Then stractive = "Y"
If stractive = "Y" Or stractive = "N" Then
Else
sErr = "Active should be Y or N"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
Dim strSql As String
Dim dblNewTotalSteps As Double
dblNewTotalSteps = dblTotalSteps + dblSteps
Dim intdays As Integer
'total # of days between start date and now
intdays = DateDiff(DateInterval.Day, Session("activeDte"), Now)
Dim intNewDays As Integer
intNewDays = intdays + 1
'subtract days out
intNewDays = (intNewDays - intDaysOut)
Dim dblNewMiles As Double
If dblNewTotalSteps <> 0 Then
dblNewMiles = dblNewTotalSteps / 2000
Else
dblNewMiles = 0
End If
'here is where I would like the messagebox to appear - if Yes, do the following. If no, drop out
If strCoach = UCase("Y") Or strName = WalkerID Then
strSql = "UPDATE walkers set "
strSql = strSql & " lastReported = @lastReported, "
strSql = strSql & "totalSteps = @totalSteps, totalDays = @totalDays, Active = @Active, Miles = @Miles, "
strSql = strSql & " added = @added, addedBy = @addedBy "
strSql = strSql & " WHERE (walker = " & "'" & WalkerID & "'" & " )"
Dim MyConn As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd As New SqlClient.SqlCommand(strSql, MyConn)
Cmd.Parameters.Add(New SqlClient.SqlParameter("@lastReported", Now))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@Active", UCase(stractive)))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@totalSteps", dblNewTotalSteps))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@totalDays", intNewDays))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@Miles", dblNewMiles))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@added", Now))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@addedBy", strName))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
'Audit
'Days = diff between last reported and today
Dim intDaysDiff As Integer
intDaysDiff = DateDiff(DateInterval.Day, dtLastReported, Now)
strSql = "insert into walkersAudit (walker, teamName, "
strSql = strSql & "Active, activeDate, lastReported, "
strSql = strSql & "totalSteps, totalDays, steps, days, miles, added, addedBy )"
strSql = strSql & "(Select walker, teamName, "
strSql = strSql & "Active, activeDate, lastReported, "
strSql = strSql & "totalSteps, totalDays, " & "'" & dblSteps & "'" & ",'" & intDaysDiff & "'" & ",'" & dblTotalMiles & "',"
strSql = strSql & " added, addedBy"
strSql = strSql & " from walkers where walker = " & "'" & WalkerID & "'" & " ) "
Dim MyConn2 As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd2 As New SqlClient.SqlCommand(strSql, MyConn2)
MyConn2.Open()
Cmd2.ExecuteNonQuery()
MyConn2.Close()
'added 2/26/08
dblSteps = 0
'strSql = ""
'deactivate user
If UCase(stractive) = "N" Then
Dim dtInactive As Date
dtInactive = Now
strSql = "insert into walkersOut Values (" & "'" & WalkerID & "', " & "'" & dtInactive & "'," & "'" & dtInactive & "'," & "'0')"
Dim MyConn3 As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd3 As New SqlClient.SqlCommand(strSql, MyConn3)
MyConn3.Open()
Cmd3.ExecuteNonQuery()
MyConn3.Close()
End If
'EditItemIndex to -1 and rebind the DataGrid
dgWalkers.EditItemIndex = -1
LoadWalkerTeamData()
If strCoach = "Y" Then
LoadInactive()
Else
LoadWalker()
End If
Else
sErr = "You do not have permission to update this walker!!!"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
Else
Dim sErr As String, spath1
sErr = "Steps must be a numeric Value"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
End Sub
not all who wander are lost....
I have a datagrid in asp.net where our users record the number of steps they have walked since last week - this works great - however - I have been asked to add a confirm button that will basically say "Are you certain you want to post xxx steps today" after the user clicks update.
Is there a way to add a messagebox to a webpage(with yes and no buttons) that will only execute the code if the user says yes?
Here is the code for my datagrid update:
Sub dgWalkers_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim strName As String
strName = LCase(Session("UserName"))
Dim strCoach As String
strCoach = Session("strCoach")
Dim dblSteps As Double
dblSteps = "0"
'check steps for numeric value
If IsNumeric(CType(e.Item.Cells(5).Controls(0), TextBox).Text) Then
Dim sErr As String, spath1
Dim WalkerID As String = e.Item.Cells(0).Text
Dim dblTotalSteps As Double = e.Item.Cells(1).Text
Dim dblTotalDays As Double = e.Item.Cells(2).Text
Dim dblTotalMiles As Double = e.Item.Cells(3).Text
Dim dtLastReported As Date = e.Item.Cells(4).Text
Dim dblSteps2 As Double = CType(e.Item.Cells(5).Controls(0), TextBox).Text
dblSteps = dblSteps2
'Dim strActive As TextBox = e.Item.Cells(6).Controls(0)
Dim stractive As String = DirectCast(e.Item.Cells(6).FindControl("txtActive"), TextBox).Text
'Dim stractive As String = e.Item.Cells(6).ID("txtactive")
' days Out - hidden column
Dim intDaysOut As Integer = e.Item.Cells(8).Text
' prevent blanks or anything other than Y or N
stractive = UCase(Trim(stractive))
If stractive = "" Then stractive = "Y"
If stractive = "Y" Or stractive = "N" Then
Else
sErr = "Active should be Y or N"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
Dim strSql As String
Dim dblNewTotalSteps As Double
dblNewTotalSteps = dblTotalSteps + dblSteps
Dim intdays As Integer
'total # of days between start date and now
intdays = DateDiff(DateInterval.Day, Session("activeDte"), Now)
Dim intNewDays As Integer
intNewDays = intdays + 1
'subtract days out
intNewDays = (intNewDays - intDaysOut)
Dim dblNewMiles As Double
If dblNewTotalSteps <> 0 Then
dblNewMiles = dblNewTotalSteps / 2000
Else
dblNewMiles = 0
End If
'here is where I would like the messagebox to appear - if Yes, do the following. If no, drop out
If strCoach = UCase("Y") Or strName = WalkerID Then
strSql = "UPDATE walkers set "
strSql = strSql & " lastReported = @lastReported, "
strSql = strSql & "totalSteps = @totalSteps, totalDays = @totalDays, Active = @Active, Miles = @Miles, "
strSql = strSql & " added = @added, addedBy = @addedBy "
strSql = strSql & " WHERE (walker = " & "'" & WalkerID & "'" & " )"
Dim MyConn As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd As New SqlClient.SqlCommand(strSql, MyConn)
Cmd.Parameters.Add(New SqlClient.SqlParameter("@lastReported", Now))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@Active", UCase(stractive)))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@totalSteps", dblNewTotalSteps))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@totalDays", intNewDays))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@Miles", dblNewMiles))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@added", Now))
Cmd.Parameters.Add(New SqlClient.SqlParameter("@addedBy", strName))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
'Audit
'Days = diff between last reported and today
Dim intDaysDiff As Integer
intDaysDiff = DateDiff(DateInterval.Day, dtLastReported, Now)
strSql = "insert into walkersAudit (walker, teamName, "
strSql = strSql & "Active, activeDate, lastReported, "
strSql = strSql & "totalSteps, totalDays, steps, days, miles, added, addedBy )"
strSql = strSql & "(Select walker, teamName, "
strSql = strSql & "Active, activeDate, lastReported, "
strSql = strSql & "totalSteps, totalDays, " & "'" & dblSteps & "'" & ",'" & intDaysDiff & "'" & ",'" & dblTotalMiles & "',"
strSql = strSql & " added, addedBy"
strSql = strSql & " from walkers where walker = " & "'" & WalkerID & "'" & " ) "
Dim MyConn2 As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd2 As New SqlClient.SqlCommand(strSql, MyConn2)
MyConn2.Open()
Cmd2.ExecuteNonQuery()
MyConn2.Close()
'added 2/26/08
dblSteps = 0
'strSql = ""
'deactivate user
If UCase(stractive) = "N" Then
Dim dtInactive As Date
dtInactive = Now
strSql = "insert into walkersOut Values (" & "'" & WalkerID & "', " & "'" & dtInactive & "'," & "'" & dtInactive & "'," & "'0')"
Dim MyConn3 As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmd3 As New SqlClient.SqlCommand(strSql, MyConn3)
MyConn3.Open()
Cmd3.ExecuteNonQuery()
MyConn3.Close()
End If
'EditItemIndex to -1 and rebind the DataGrid
dgWalkers.EditItemIndex = -1
LoadWalkerTeamData()
If strCoach = "Y" Then
LoadInactive()
Else
LoadWalker()
End If
Else
sErr = "You do not have permission to update this walker!!!"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
Else
Dim sErr As String, spath1
sErr = "Steps must be a numeric Value"
If sErr <> "" Then
spath1 = "<script language='javascript'>alert('"
spath1 = spath1 + sErr
spath1 = spath1 + "');</script>"
Page.RegisterStartupScript("sPath1", spath1)
Exit Sub
End If
End If
End Sub
not all who wander are lost....