Accessing C# Variables in JavaScript

Posted by mshahbazm on Stack Overflow See other posts from Stack Overflow or by mshahbazm
Published on 2012-11-25T16:56:35Z Indexed on 2012/11/25 17:04 UTC
Read the original article Hit count: 257

Filed under:
|
|

I am Developing Windows 8 application in which i have to access variables of C# class in java script function, But Unfortunately i don not know how to do this: My C# class code is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pakistan_Tour
{
   public class UniversalValues
{
   public static double xC;
   public static double yC;

public  static  int selectedcity;

     public int retcity() 
    {
        return selectedcity;

    }
    public void setcity(int val)
    {
         selectedcity=val;
    }
    public void setxy(double x, double y)
    {
        xC = x;
        yC = y;

    }
    public double getx()
    {
        return xC;
    }
    public double gety()
    {
        return yC;
    }


 }
}

I have to access the value of variables: xC and yc in java script I am doing like:

 function initialize() {

        var x = "<%=xC%>";

        var y = "<%=yC%>";
}

but is not working, Kindly help me with this, Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript