problem in reading server side string from client

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?
 
K

Karl Seguin

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top