我正在从 asp.net(vb) 中的代码隐藏生成一个 javascript 警报框。
编码:
Catch ex As Exception
MesgBox("Error in uploading file due to following exception" & vbNewLine & ex.ToString)
trans.Rollback()
Finally
conn.Close()
End Try
消息框功能如下:
Private Sub MesgBox(ByVal sMessage As String)
Dim msgedtble As String = sMessage.Replace("\", "\\")
msgedtble = msgedtble.Replace(vbNewLine, "\n")
Page.ClientScript.RegisterStartupScript(Me.GetType,
"myScripts",
"<script language='javascript'>alert('" & msgedtble & "');</script>")
End Sub
现在,当抛出异常时,以下脚本将附加在客户端 html 的 form 标记中:
<script language='javascript'>alert('Error in uploading file due to following exception\nSystem.Data.SqlClient.SqlException (0x80131904): Violation of UNIQUE KEY constraint 'IX_AccountMaster'. Cannot insert duplicate key in object 'dbo.AccountMaster'.\nThe statement has been terminated.\n at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)\n at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)\n at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)\n at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)\n at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)\n at UploadAccountMasterXl.Button1_Click(Object sender, EventArgs e) in C:\\Users\\ssaa\\Documents\\Visual Studio 2010\\WebSites\\Dpp2012\\UploadAccountMasterXl.aspx.vb:line 57');</script>
为什么这没有出现在我的浏览器(Firefox)中?