Got this error while call the function
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
Calling this function:
string sampledata = "Name :zzzzzzzzzzzzzzzz<br>Phone :00000000000000<br>Country :India";
string sample = sampledata.Replace("<br>", "\n");
MsgBox.DisplayAJAXMessage(this, sample);
I need to display Name,Phone and Country in next line.
Got this error while call the function
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
Calling this function:
string sampledata = "Name :zzzzzzzzzzzzzzzz<br>Phone :00000000000000<br>Country :India";
string sample = sampledata.Replace("<br>", "\n");
MsgBox.DisplayAJAXMessage(this, sample);
I need to display Name,Phone and Country in next line.
Share Improve this question asked Aug 13, 2012 at 6:58 Prince Antony GPrince Antony G 9324 gold badges18 silver badges39 bronze badges4 Answers
Reset to default 9Unterminated string constant means you've forgotten to close your string. You can't have an alert that runs over multiple lines. When the script is outputting to the browser, it's actually including the new lines.. not the "\n" like the javascript expects. That means, your alert call is going over multiple lines.. like this:
alert('Name :zzzzzzzzzzzzzzzz
Phone :00000000000000
Country :India');
..which won't work, and will produce the error you're seeing. Try using double backslash to escape the backslash:
string sample = sampledata.Replace("<br>", "\\n");
"\n"
is a newline for C#, i.e. your js contains:
something('...blah foo
bar ...');
what you actually want is a newline in js:
something('...blah foo\nbar ...');
which you can do with:
string sample = sampledata.Replace("<br>", "\\n");
or:
string sample = sampledata.Replace("<br>", @"\n");
You need to escape/encode your string being consumed by JavaScript
:
Escape Quote in C# for javascript consumption
Your Unterminated is not in C# is in Javascript generated code.