3

I want to use Encrypt(myString) from C# in JS code.

Is this possible?

I tried something like that:

In C#

public object IDToUrl(int myNumber)
    {
        return Encrypt(myNumber.ToString());
    }

In JS

var encryptedValue = '<%=IDToUrl(data.id)%>';

but it doesn't work.

2
  • What methodology are you using to serve your HTML? WebForms or MVC? Are you trying to use your '<%=IDToUrl(data.id)%>'; in a .js page, or in your HTML page? Commented Jul 30, 2014 at 14:00
  • WebForms Sir, but I did it, thanks for all. Commented Jul 31, 2014 at 3:14

1 Answer 1

1

That code would only work if that IDToUrl() method is local to that page. You don't state what view you are using, but I would solve this with a helper class.

Add a Helper class like this:

public static class SomeNameHelper
{
   public static object IDToUrl(int myNumber)
   {
      return Encrypt(myNumber.ToString());
   }
   public static object Encrypt(string s){
      ... whatever code that is required...
   }
}

In js:

var encryptedValue = '<%=SomeNameHelper.IDToUrl(data.id)%>';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.