1

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.

1

2 Answers 2

2

Here is a walkthrough about calling C# from JS. Also, take a look at this question.

Sign up to request clarification or add additional context in comments.

Comments

0

Try passing c# vaiables as parameters to your JS function

<script type="text/javascript">
    generateMarkersForSideBar(<%=this.LatLangStringForMap%>);
</script>

and in cs code

string _LatLangStringForMap;
public string LatLangStringForMap
{
  get { return _LatLangStringForMap; }
  set { _LatLangStringForMap = value; }
}

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.