C # variable access in javascript

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

On one of my ASPX pages, I want to disable the menu that is in JavaScript, according to accessright.

accessrightis stored in the database table loginas a single attribute on the SQL server, and I want to get this accessrightfor a single C # variable and want to access this variable in JavaScript.

If there is another possible approach, please advise.

+3
source share
5 answers

, ASP-, ASP.NET
codebehind say public int MyInteger
aspx

<script>
    function GetMyValue()
    {
     var someVar = <%=this.MyInteger%>;
     //Do something
    }
</script>
+10

silde Javascript. - eval() javascript:

function GetMyValue(){      
    eval("var someVar = " + parseInt<%=this.MyInteger%>"));
    //Do something     
} 

. ;)

+2

, . http://www.eggheadcafe.com/community/aspnet/7/63763/using-c-variable-in-java.aspx . strvariable - #.

    <INPUT id="hd" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 144px" type="hidden"  value="<%=strvariable %>">

<script language="javascript">
function Button_Click()
{
    alert(document.getElementById('hd').value); 
}
</script>
+1

. - AJAX script.

:

string script = string.Format("var myVariable = '{0}';", vaiable.ToString());
if (!ClientScript.IsClientScriptBlockRegistered("myScript"))
{
    ClientScript.RegisterClientScriptBlock(typeof(_Default), "myScript", script, true);
}

javascript myVariable .

.

0

RemoteInvoke, javascript . , .

javascript , . , RemoteInvokable, , . , , , , (.. arg, , , .

RemoteInvoke.

0

Source: https://habr.com/ru/post/1705083/


All Articles