从 Javascript 调用函数背后的代码

发布于 2025-01-07 19:39:24 字数 326 浏览 3 评论 0原文

我想从 javascript 调用或触发函数后面的代码。我使用这段代码:

var item = <% fillHistoryGrid() %> ;

但是当我这样写时,我收到错误:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 

注意:我的函数后面的代码开始:Public Sub ....

我应该做什么?

I want to call or fire code behind function from javascript. I use this code :

var item = <% fillHistoryGrid() %> ;

but when i write like this, i get error :

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 

Note : my code behind function starts : Public Sub ....

What should i do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

|煩躁 2025-01-14 19:39:24

您使用的模板引擎是什么(ASP、JSP、某些 JavaScript 引擎)?这应该支持这样的要求,语法很可能看起来像 <%= %>

What is the templating engine you are using (ASP, JSP, some JavaScript one)? That should support such requirements, most likely the syntax will look like <%= %>

悍妇囚夫 2025-01-14 19:39:24

如果您使用 c#/vb.net 并在 asp.net 中的 javascript 中调用代码隐藏函数
您的函数背后的代码必须是静态的(如果 vb.net 则共享)

public static void funname()
{
}

并在 javascript 中调用 funname
通过使用

PageMethods.funname()

'

if you are using c#/vb.net and calling code-behind function in javascript in asp.net
your code behind function must be static (shared if vb.net)

public static void funname()
{
}

and call funname in javascript
by using

PageMethods.funname()

'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文