从Jquery的方法后面调用代码 [英] Call code behind method from Jquery

查看:98
本文介绍了从Jquery的方法后面调用代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题:

如何从jquery调用codebehind方法?我有一个网页:(ForgetPass.aspx)及其背后的代码(ForgetPass.aspx.cs).在后面的代码中,我有一个公共方法:

How could I call a codebehind method from jquery? I have a web page: (ForgetPass.aspx) with its respective codebehind (ForgetPass.aspx.cs). On the codebehind I have a public method:

public void ChangeSession(string strChangeSession)
    { some stuff... }

当我使用MVC时,调用该方法非常简单:

When I was working on MVC, calling that method was as simple as:

$.post("MyPageController/ChangeSession", { strChangeSession: 'yes' });

但是现在我在aspx/C#上,我不知道如何从jquery调用该方法(或者也许我需要在代码??上使用[WebMethod]子句?)

But now that I'm on aspx/C# I don't know how to call that method from jquery (or maybe I need to use [WebMethod] clause on the codebehind ??)

先谢谢了.

推荐答案

是的,您将需要[WebMethod]并且它也必须是静态的,请阅读教程以获取有关这些位的说明.

Yes you'll need [WebMethod] and it'll need to be static as well, read the tutorial for an explanation on these bits.

根据您的方法名称,您可能需要以下内容:

Based on your method names, you'll probably need this:

[WebMethod (EnableSession = true)] //Allows access to session state
public void ChangeSession(string strChangeSession)
{ some stuff... }

这篇关于从Jquery的方法后面调用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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