【问题标题】:error handle gridview in updatepanel asp.netupdatepanel asp.net 中的错误句柄 gridview
【发布时间】:2017-07-28 05:14:11
【问题描述】:

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

当 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

【问题讨论】:

  • 你还没有提供你的代码。
  • 您能否针对您的问题创建minimal reproducible exampleadd 它?我认为这将有助于更清楚地展示您的问题。您当前是否在 GridView2_RowDeleted 事件中捕获异常,或者它们是否被抛出? (需要知道我们必须处理什么)

标签: asp.net gridview updatepanel scriptmanager registerstartupscript


【解决方案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

【讨论】:

    猜你喜欢
    • 2011-01-31
    • 2012-11-11
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 2011-12-28
    • 2011-03-31
    相关资源
    最近更新 更多