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.
- <html>
- <body>
- <script language="javascript">
- alert('Hi, Good Morning\nWelcome To C-SharpCorner');
- </script>
- </body>
- </html>
Output:
Or, you can show the text in Multiline like this.
- <html>
- <body>
- <script language="javascript">
- alert( "ID = 101" + '\n' +
- "NAME = Georgie" + '\n' +
- "GENDER = Male"
- );
- </script>
- </body>
- </html>
Output:
Now, If you want to show to JavaScript Alert box using C# code.
- dispalyAlert("Hello.\\n\\This is the Example of Multiple line JavaScript Alert box in C#.");
- private void dispalyAlert(string message) {
- string script = "alert('" + message + "');";
- ScriptManager.RegisterStartupScript(this, typeof(Page), "UserSecurity", script, true);
- }