c#函数通过javascript调用 [英] c# functions call through javascript

查看:73
本文介绍了c#函数通过javascript调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过java脚本调用c#函数...... plz回复我...

How to call c# function by java script......plz reply me...

推荐答案

嘿伙计,请访问以下链接..希望能帮助您解决问题。



致电来自javascript的函数代码

[ ^ ]



从JavaScript调用代码隐藏函数 [ ^ ]
Hey dude,Kindly visit the following links.. Hope that will help you solve your problem.

calling code behind function from javascript
[^]

Calling a code-behind function from JavaScript[^]


你可以试试这个:

You may try this :
Page.ClientScript.RegisterStartupScript(this.GetType(),"Call my function","MyFunction()",true);



更多细节请访问这里....

http://stackoverflow.com/questions/5731224/calling-javascript-function-from-codebehind [ ^ ]

http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/calling -an-Asp-Net-C-Sharp-method-web-method-using-javascript / [ ^ ]


它是非常直接使用_来自Javascript的_doPostBack调用。



在代码后面的Page_Load函数中,添加:



It's quite straightforward using the __doPostBack call from Javascript.

In the Page_Load function in your code behind, put:

protected void Page_Load(object sender, EventArgs e)
{
    // ensure page always includes the __doPostBack function
// (best to put this in your Master Page, if you have one)
    Page.ClientScript.GetPostBackEventReference(this, string.Empty);

// now test if a postback event occurred
if (Page.IsPostBack)
{
            // postback occurred, so determine which function name was called
            switch (Request.Form["__EVENTTARGET"])
            {
                case "myProcedure1":
                    {
                        // go and call your function
                        doMyProcedure1(Request.Form["__EVENTARGUMENT"]);

                        break;
                    }
    }
}
}





然后再往下走在你的代码中,创建你想要调用的C#函数:





Then further down in your code behind, create the C# function you wish to call:

protected void doMyProcedure1(String someVar)
{
// do your function code here
String passedVar = someVar;
}





然后最后在你的Javascript中,做一个调用C#函数的回发:





Then finally in your Javascript, do the postback that calls the C# function:

function callMyFunction()
{
__doPostBack('myProcedure1', 'some string');
}


这篇关于c#函数通过javascript调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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