简体   繁体   中英

Calling ascx.cs method from ascx page using javascript

I have a code behind file which contains a method:

public string ProductsAsJson()

which returns a json representation of a series of products. I want to be able to use some angular functions in my ascx page and so I am trying to call the function using:

 <script type="text/javascript">

   var products = <%# ProductsAsJson() %>;

but it is failing to retrieve the list of products.

What am I a doing wrong?

您可以将ProductsAsJson()的返回值存储在公共变量中,并在.cs页面加载时调用此方法,并在ascx控件中访问变量的值并分配给javascript变量。

var products = <%# ProductsAsJson %>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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