ASP.NET调用code从JavaScript函数的背后 [英] Calling ASP.NET Code Behind function from JavaScript

查看:105
本文介绍了ASP.NET调用code从JavaScript函数的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从JavaScript调用ASP.NET codebehind功能。

Is it possible to call ASP.NET codebehind function from JavaScript.

推荐答案

我想preFER穆罕默德·阿赫塔尔PageMethod的方法。只要一短信:你不需要使用ScriptManager。使用ScriptManager只为您生成JavaScript代理方法。如果你已经有JQuery的页面上,你可以忘掉的ScriptManager,写这样的事情在页面上,而不是:

I would prefer Muhammad Akhtar PageMethod approach. Just one short note: You don't need the scriptmanager. The scriptmanager only generates the javascript proxy methods for you. If you already have JQuery on your page, you can forget about the scriptmanager and write something like this on your page instead:

<script type ="text/javascript">
    $(document).ready(function() {
        $("#AjaxLink").click(function(e) {
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: "YourPage.aspx/updateContent",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(result) {
                    $("#content").html(result.d);
                }
            });
        });
     });
</script>

这是假定你有你的页面上的ID AjaxLink的链接以及与该ID的内容,显示结果的DIV。
这样做的好处是,你保存的javascript 30KB比较了ScriptManager的jQuery和注入脚本之间

this assumes that you have a link with the ID AjaxLink on your page as well as a div with the id content that shows the result. The benefit is that you save 30kb javascript compared between jquery and the injected scripts by the scriptmanager

这篇关于ASP.NET调用code从JavaScript函数的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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