0

I have an ASPX.CS code:

Protected int myprop

I would like to call it on a JS assignment :

<script type='text/javascript'>
...
 data.add(['SomeJSProperty', "<%..myprop from code behind%>"]);

I remember doing it with <% %> inline code and it used to view the code behind protected and public members. but it won't work now.

Thanks

1
  • BTW, that's not calling code behind member from JavaScript, mind you. That will just render the output of the expression enclosed within <%= %> in your JavaScript, and that happens before the JavaScript code block is run. Commented Mar 19, 2012 at 10:36

2 Answers 2

2

Try this:

<script type='text/javascript'>
...
data.add(['SomeJSProperty', "<%= myprop %>"]);

More info on MSDN.

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

3 Comments

Hi, I tried this but from some reason I am getting this error:The Controls collection cannot be modified because the control contains code blocks
Add more code to the question then. The info you gave is not enough to solve your problem.
had to warp the <script> with a runat=server control
0

In the page_load you can add a input type='hidden' value='my prop' to the page. and from javascript when document is ready you can simply read that value from the hidden input.

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.