Javascript – Accessing C# variable in javascript


I'm going to design a website for DMS (educational domain) in C#.NET, which I am new to.

In one of my ASPX pages, I want to disable a menu, which is in JavaScript, according to accessright.

The accessright stored in database table login as one attribute in SQL server, and I want to retrieve that accessright to one C# variable and want to access that variable in JavaScript.

If there is another possible approach please tell.

Best Answer

Well there is one shortcut we used to use during the ASP days, this still works in ASP.NET
In the page codebehind declare a public property say public int MyInteger
In the aspx put this

    function GetMyValue()
     var someVar = <%=this.MyInteger%>;
     //Do something