I had a jscript alert box being shown in one of my web projects, but I wanted to format the text so that some text appeared on a new line. I knew the \n would insert a new line character for me, but the code was failing, not even showing the alert box.
I then remembered that you need to escape the escape sequence! In other words, you have to put in a double slash (\\). Here's the code:
System.Text.StringBuilder msg = new System.Text.StringBuilder();msg.Append("<script>");msg.Append("alert(\"You chose date: " + Calendar1.SelectedDate.ToString("d") + ".\\n");
msg.Append("The earliest collection date is tomorrow (" + Calendar1.SelectedDate.AddDays(1).ToString("d") + ").\\n");
msg.Append("Please choose another date\")");msg.Append("</script>");Response.Write(msg.ToString());
No comments:
Post a Comment