D
Dave
I am beginning to write some C# pages to an app I created with VB.Net.
There is one VB routine I use frequently - a javascript alert box. I have
created a C# version, but it does not handle newlines. I get an
"unterminated string constant" error message. Googling this problem gives
some hints that there are others with this problem, but I could not find a
solution.
In addition to this method, I tried the RegisterClientScriptBlock way, but
get the same results. I have also tried several ways of building the string
(enclosing with single quotes & double quotes, the ToString() method, etc.)
without success. I should add that I can use the C# routine without
incident if I pass a normal string variable. It's only when I pass in a
newline character (and I suspect other escaped characters) that the problem
occurs.
I am enclosing some code below. If somebody could help me out with this
problem, I would greatly appreciate it.
First VB.Net:
Public Sub DisplayAlert(ByVal msg As String)
response.write("<script language=JavaScript> alert('" & msg & "'); <" &
"/script>")
end sub
Calling this routine the following way gives the expected result:
dim s as string = "Line 1\n\rLine 2"
DisplayAlert( s )
Result:
Line 1
Line 2
----------------------------------------------------------------
----------------------------------------------------------------
Now in C#:
private void DisplayAlert(string msg)
{
Response.Write("<script language=JavaScript> alert('" + msg + "'); <" +
"/script>");
}
Calling this routine the following way gives the 'unterminated string
constant' error.
string s = "Line 1\nLine 2";
DisplayAlert( s );
Can anyone help me?
Thanks,
Dave
There is one VB routine I use frequently - a javascript alert box. I have
created a C# version, but it does not handle newlines. I get an
"unterminated string constant" error message. Googling this problem gives
some hints that there are others with this problem, but I could not find a
solution.
In addition to this method, I tried the RegisterClientScriptBlock way, but
get the same results. I have also tried several ways of building the string
(enclosing with single quotes & double quotes, the ToString() method, etc.)
without success. I should add that I can use the C# routine without
incident if I pass a normal string variable. It's only when I pass in a
newline character (and I suspect other escaped characters) that the problem
occurs.
I am enclosing some code below. If somebody could help me out with this
problem, I would greatly appreciate it.
First VB.Net:
Public Sub DisplayAlert(ByVal msg As String)
response.write("<script language=JavaScript> alert('" & msg & "'); <" &
"/script>")
end sub
Calling this routine the following way gives the expected result:
dim s as string = "Line 1\n\rLine 2"
DisplayAlert( s )
Result:
Line 1
Line 2
----------------------------------------------------------------
----------------------------------------------------------------
Now in C#:
private void DisplayAlert(string msg)
{
Response.Write("<script language=JavaScript> alert('" + msg + "'); <" +
"/script>");
}
Calling this routine the following way gives the 'unterminated string
constant' error.
string s = "Line 1\nLine 2";
DisplayAlert( s );
Can anyone help me?
Thanks,
Dave