简体   繁体   English

从javascript调用成员后面的代码

[英]calling a code behind member from javascript

I have an ASPX.CS code: 我有一个ASPX.CS代码:

Protected int myprop

I would like to call it on a JS assignment : 我想在JS任务上调用它:

<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 谢谢

Try this: 尝试这个:

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

More info on MSDN . 有关MSDN的更多信息。

In the page_load you can add a input type='hidden' value='my prop' to the page. 在page_load中,您可以向页面添加输入类型='hidden'value ='my prop'。 and from javascript when document is ready you can simply read that value from the hidden input. 从文档准备就绪的javascript中,你可以简单地从隐藏的输入中读取该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM