在asp.net中添加Java脚本函数 [英] add java script function in asp.net

查看:71
本文介绍了在asp.net中添加Java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我添加了这个

hi every one
i add this

<script type="text/javascript">
function g(par)
{
    if (par==''d'')
    {
        alert(''d'');
        <% dd();%>; // call c# method  
    } 
}
</script>


到aps.net
形式加载时该功能必须提高

为什么?


to aps.net
whay in form load this function must raise

why?

推荐答案

我认为您需要使用Page.GetPostBackEventReference()发布表单,以便可以在服务器端调用方法.

请参见 [ ^ ]

祝你好运;
i think that you need to use Page.GetPostBackEventReference() to post your form so you can call methods on Server-Side.

See this [^]

good luck;


您对何时何地评估什么感到困惑.您显示给我们的代码段来自ASP.net aspx页面.该页面以及文件背后的代码在服务器端运行.输出将呈现为HTML,包括您在aspx页面中具有的javascript.包含在javascript块中的标签也只会在服务器端进行评估.因此,您所获得的只是在服务器上的执行时调用了dd()方法.如果要在客户端执行javascript时调用服务器端方法,则必须使用ASP.NET回发或AJAX.

问候,

-MRB
You have some confusion about what is evaluated when and where. The code snippet you showed us is from your ASP.net aspx page. This page in conjunction with the code behind file is run on the server side. The output is being rendered to HTML including the javascript you have in your aspx page. The tags you included inside the javascript block are also only evaluated on the server side. So all you achieved is that the method dd() is being called at the execution time on the server. If you want to call a server side method while the javascript is being exeuted on the client you''d have to use ASP.NET postback or AJAX.

Regards,

-MRB


我同意第一种解决方案.您可能想使用AJAX完成此任务.阅读有关PageMethods的更多信息.以下是一些可帮助您入门的链接.
在ASP.NET AJAX中使用PageMethods和JSON [使用Ajax从客户端调用服务器端代码 [使用jQuery直接调用ASP.NET AJAX页面方法 [ ^ ]
I agree with the 1st solution. You might want to use AJAX to accomplish this task. Read more about PageMethods. Here are some links to get you started.
Using PageMethods and JSON in ASP.NET AJAX[^]
Calling Server Side Code from Client Side using Ajax[^]

Alternatively, you can also use JQuery to do this. See below.
Using jQuery to directly call ASP.NET AJAX page methods[^]


这篇关于在asp.net中添加Java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆