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 Code-behind (C#) code.
Display the Multi line message in Alert Box using JavaScript Code.
<html>
<body>
<script
language="javascript">
alert('Hi, Good Morning\nWelcome To C-SharpCorner');
</script>
</body>
</html>
Output:
![alertbox-in-javascript.png]()
Or, you can show the text in Mulitline like this.
<html>
<body>
<script
language="javascript">
alert( "ID = 101" +
'\n' +
"NAME = Georgie" +
'\n' +
"GENDER = Male"
);
</script>
</body>
</html>
Output:
![multiline-alert-box.png]()
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);
}