Using JavaScript methods in C#

by Filip 6/4/2008 5:09:00 PM

I ran into a weird problem today.  I needed to escape a string in c# in such a way as to be able to unescape() it later with JavaScript into the original string.  JavaScript has an escape() method that is able to do this, but since I'm writing the code in C#, I can't really access that method.  At first, I looked into HttpServerUtility.UrlEncode() and the HttpServerUtility.HtmlEncode() methods, but those are not equivalent to JavaScript's escape() method. 

However, it seems Microsoft has put in a library which gives us access to JavaScript methods ( whether this is simply mimicking what JavaScript does or if it actually uses JavaScript... I could really care less).  All that was needed is a reference to Microsoft.JScript in the project, and I was able to call the Microsoft.JScript.GlobalObject.escape() method, and it produces the exact same output as the JavaScript version.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Web Development

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/28/2008 7:02:42 PM

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen

About Filip Stanek

Death Note Pic I'm a developer at ACG Multimedia in Cincinnati, OH. Besides working with ASP.NET, Flash, and other web technologies, I enjoy playing chess, Rockband, and keeping up with the recent events (US elections this year are actually fun!).
E-mail me Send mail


Recent comments