Introduction

Many times we need to show a message in the JavaScript Alert box and want to display the message in the multi-line or multiple lines.
This blog is about how to display the JavaScript Popup box with Multiple text lines through JavaScript and also using the Code-behind (C#) code.
Display the Multiline message in Alert Box using JavaScript Code.
  1. <html>
  2. <body>
  3. <script language="javascript">
  4. alert('Hi, Good Morning\nWelcome To C-SharpCorner');
  5. </script>
  6. </body>
  7. </html>
Output:
alertbox-in-javascript.png
Or, you can show the text in Multiline like this.
  1. <html>
  2. <body>
  3. <script language="javascript">
  4. alert( "ID = 101" + '\n' +
  5. "NAME = Georgie" + '\n' +
  6. "GENDER = Male"
  7. );
  8. </script>
  9. </body>
  10. </html>
Output:
multiline-alert-box.png
Now, If you want to show to JavaScript Alert box using C# code.
  1. dispalyAlert("Hello.\\n\\This is the Example of Multiple line JavaScript Alert box in C#.");
  2. private void dispalyAlert(string message) {
  3. string script = "alert('" + message + "');";
  4. ScriptManager.RegisterStartupScript(this, typeof(Page), "UserSecurity", script, true);
  5. }