title: Javascript alert not working from code behind
body: <p>I am generating a javascript alert box from codebehind in asp.net(vb). </p>
  
  <p>The code:</p>
  
  <pre><code>            Catch ex As Exception
                  MesgBox("Error in uploading file due to following exception" &amp; vbNewLine &amp; ex.ToString)
                  trans.Rollback()
              Finally
                  conn.Close()
              End Try
  </code></pre>
  
  <p>The mesgbox function is as follows:</p>
  
  <pre><code>Private Sub MesgBox(ByVal sMessage As String)
      Dim msgedtble As String = sMessage.Replace("\", "\\")
      msgedtble = msgedtble.Replace(vbNewLine, "\n")
      Page.ClientScript.RegisterStartupScript(Me.GetType,
   "myScripts",
   "&lt;script language='javascript'&gt;alert('" &amp; msgedtble &amp; "');&lt;/script&gt;")
  
  End Sub
  </code></pre>
  
  <p>Now when exception is thrown, the following script is appended in the form tag of the client side html :</p>
  
  <pre><code>        &lt;script language='javascript'&gt;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');&lt;/script&gt;
  </code></pre>
  
  <p>Why is this not appearing in my browser(Firefox)?</p>