problem in reading server side string from client

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have an aspx page in the code behind i have
in aspx.cs
public string sPath = "C:\\Public\\User\\Other";

is aspx when I tried to get the string the slahes is gone i tried to alert
the string it gave me C:PublicUserOther , why?

<script language=javascript>
function CreateFolder()
{
var Path = '<%= sPath %>'l
alert('<%= sPath %>');
}
</script>

any help?
 
Raed:
Javascript, like C#, uses \ to escape values. So when you do
c:\\something\\else in c#, the string value is actually c:\something\else.
However, javascript also needs slashes escapes.

Two solutions is to change your string to:

"c:\\\\public\\\\user\\\\other";

or to escape it via:

@"c:\\public\\user\\other";

You should probably create a utility function which takes a string and
prepares it for javascript, namely escaping slashes as well as single
quotes.

Hope this helps
Karl
 
Thank u worked perfectly

Karl Seguin said:
Raed:
Javascript, like C#, uses \ to escape values. So when you do
c:\\something\\else in c#, the string value is actually c:\something\else.
However, javascript also needs slashes escapes.

Two solutions is to change your string to:

"c:\\\\public\\\\user\\\\other";

or to escape it via:

@"c:\\public\\user\\other";

You should probably create a utility function which takes a string and
prepares it for javascript, namely escaping slashes as well as single
quotes.

Hope this helps
Karl
 
Back
Top