1

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.

3
  • Constants.cs is your custom class? Commented Nov 11, 2015 at 9:36
  • Hi Atish, yes it is. Commented Nov 12, 2015 at 3:45
  • Have a look into my answer Commented Nov 12, 2015 at 3:51

1 Answer 1

1

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.

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.