I put a gridview in an updatepanel. When user del a row that will cause a FK error, there will be no any message and error page showup because asyncpostback updatepanel.
I put an ScriptManager.RegisterStartupScript to show some message in the GridView2_RowDeleted event when e.AffectedRows=0.But it also not work(nothing happen). I think maybe SQL error happen before GridView2_RowDeleted event.
So, May someone give me some idear to this situation? What I need is to show message like alert or lable.text when a SQL error happen(gridview in updatepanel )
By now here is the code of 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
Thanks everyone to reply me. The alert dont showup because of two problems first:e.message.tostring maybe exist some word that affect alert message string.
second:we need "e.ExceptionHandled = True" to hanlde error ourself
I find the answer below.