0

我在更新面板中放置了一个网格视图。当用户删除将导致 FK 错误的行时,将不会显示任何消息和错误页面,因为 asyncpostback 更新面板。

当 e.AffectedRows=0 时,我放置了一个 ScriptManager.RegisterStartupScript 以在 GridView2_RowDeleted 事件中显示一些消息。但它也不起作用(没有任何反应)。我认为可能在 GridView2_RowDeleted 事件之前发生 SQL 错误。

那么,有人可以给我一些想法吗?我需要的是在发生 SQL 错误时显示警报或 lable.text 之类的消息(更新面板中的网格视图)

现在这里是 GridView2_RowDeleted 的代码

    Private Sub GridView2_RowDeleted(sender As Object, e As GridViewDeletedEventArgs) Handles GridView2.RowDeleted

    If e.AffectedRows = 0 Then
        Label14.Text = "Can't Del because still material in this storage!"
        ScriptManager.RegisterStartupScript(Me.UpdatePanel2, Me.UpdatePanel2.GetType(), "mykey", "alert('Error:" & "Can't Del because still material in this storage!" & "');", True)
        UpdatePanel2.Update()            
    End If
End Sub
4

1 回答 1

-1

谢谢大家回复我。警报不显示首先是因为两个问题:e.message.tostring 可能存在一些影响警报消息字符串的单词。

第二:我们需要“e.ExceptionHandled = True”来自己处理错误

我在下面找到答案。

Private Sub GridView1_RowDeleted(sender As Object, e As GridViewDeletedEventArgs) Handles GridView1.RowDeleted
    If (e.Exception Is Nothing) Then
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('del 1 rec');", True)
        GridView1.SelectedIndex = -1
    Else
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('Error:del 0 rec');", True)
       e.ExceptionHandled = True
    End If

End Sub
于 2017-03-09T20:18:01.227 回答