我正在從asp.net(vb)中的代碼隱藏中生成一個JavaScript警告框。Javascript alert not working from code behind
的代碼:
Catch ex As Exception
MesgBox("Error in uploading file due to following exception" & vbNewLine & ex.ToString)
trans.Rollback()
Finally
conn.Close()
End Try
的mesgbox功能如下:
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形式的標籤所附:
<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)中?
另外,它是VB.NET,所以它應該是'Imports System.Web.Script.Serialization',它應該在文件的開頭 – freefaller
我相信JavaScriptSerializer會添加引號。我是一個PHP人,我知道json_encode添加了引號。 –
@freefaller編輯... –