Is there a way to retrieve a constant from a Constants.cs file by using javascript? I can retrieve the my constant in my ascx page using Constants.Lists.DisplayName.MyList. I was wondering if I can reuse the same method of calling the list in javascript. I am currently using JSOM and I would need the list name as one of my parameters.
1 Answer
In .ascx, add Literal:
<asp:Literal runat="server" ID="MyListName" Mode="PassThrough" />
Then in .cs, add value for that control like this, e.g., in OnInit:
MyListName.Text = "<script type='text/javascript'>var myListName='" + Constants.Lists.DisplayName.MyList + "';</script>";
Finally in JS, use myListName variable like a boss.
Constants.csis your custom class?