Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8182573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:54:05+00:00 2026-06-07T00:54:05+00:00

I am generating a javascript alert box from codebehind in asp.net(vb). The code: Catch

  • 0

I am generating a javascript alert box from codebehind in asp.net(vb).

The code:

            Catch ex As Exception
                MesgBox("Error in uploading file due to following exception" & vbNewLine & ex.ToString)
                trans.Rollback()
            Finally
                conn.Close()
            End Try

The mesgbox function is as follows:

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

Now when exception is thrown, the following script is appended in the form tag of the client side 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>

Why is this not appearing in my browser(Firefox)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:54:06+00:00Added an answer on June 7, 2026 at 12:54 am

    Add Imports System.Web.Script.Serialization to the top of your file, then try this:

    Private Sub MesgBox(ByVal sMessage As String)
        Dim serializer as New JavaScriptSerializer()
        Dim msgedtble As String = serializer.Serialize(sMessage)
        Page.ClientScript.RegisterStartupScript(Me.GetType, "myScripts",
            "<script type='text/javascript'>alert(" & msgedtble & ");</script>")
    End Sub
    

    Using JavaScriptSerializer should take care of the linebreaks, single quotes, and everything else we haven’t already thought of.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm generating a JavaScript alert with following code in C# .NET page: Response.Write(<script language=JavaScript>
Do you know of a .NET library for generating javascript code? I want to
I am generating JavaScript pages through Java code like: FileOutputStream fs=new FileOutputStream(C:\\Documents and Settings\\prajakta\\Desktop\\searcheng.html);
Performance issue, when generating around 800~ options from jSon object via javascript. Any suggestion,
Are there any .Net components for obfuscating JavaScript? I'm generating JavaScript dynamically & emitting
I'm generating some javascript in my PHP code, and I need to assign some
Possible Duplicate: Generating a JavaScript array from a PHP array I just want to
Does anyone have Javascript code for generating all variations with repetition? Example of variations
Via PHP, i'm generating some JavaScript code, witch looks like this: <script type=text/javascript> $(window).load(function()
I have a rails template (.rhtml file) generating a Javascript object. It looks something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.