如何从C#Webmethod调用Javascript方法? [英] How can I Call Javascript method from C# Webmethod?

查看:51
本文介绍了如何从C#Webmethod调用Javascript方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的网络方法:

(这个WebMethod是从其他页面的JavaScript函数调用的)



 [WebMethod] 
public static string SetFileName( string FileName)
{
// < span class =code-comment>这里我想调用JavaScript方法
}





这是我想从WebMethod调用的Javascript方法:

(以上WebMethod和以下JavaScript函数在同一页面)



  function  Checking(){
// 一些代码显示图像
}





你能帮忙吗我???

解试方案

试试这个.. :)



  function  RunCode()
var FileName = 任何东西;


.ajax({
type: POST
url: Default.aspx / SetFileName
contentType: application / json; charset = utf-8
数据: {'FileName':' + FileName + '}
dataType: json
成功:功能(数据){

Checking();

},
错误:功能(结果){
/ / alert(登录错误);

}
});
}

function Checking(){
// 一些显示图像的代码
}





< pre lang =c#> [WebMethod]
public static string SetFileName( string FileName)
{
// 这里我想调用JavaScript方法
}


你好,



使用以下行从代码隐藏文件中调用Javascript函数。

 ScriptManager.RegisterStartupScript(页面,页面.GetType(),key,functionNameWithBrackets +;,true); 



你也可以使用Key:

 ScriptManager.RegisterStartupScript(page,page.GetType(),key,functionNameWit hBrackets +;,true); 



调用函数时键值应该很有趣。


I have a webmethod like this :
(This WebMethod is called from other page's JavaScript Function)

[WebMethod]
    public static string SetFileName(string FileName)
    {
        //Here I want to call JavaScript Method
    }



This is Javascript Method which I want to call from WebMethod :
(The above WebMethod & following JavaScript Function are in same page)

function Checking() {
           //Some Codes to display images
           }



Can you please help me???

解决方案

try this.. :)

 function RunCode()
var FileName="anything";


.ajax({ type: "POST", url: "Default.aspx/SetFileName", contentType: "application/json;charset=utf-8", data: "{'FileName':'" + FileName + "'}", dataType: "json", success: function (data) { Checking(); }, error: function (result) { //alert("Error login"); } }); } function Checking() { //Some Codes to display images }



[WebMethod]
    public static string SetFileName(string FileName)
    {
        //Here I want to call JavaScript Method
    }


Hi,

Use the below line to call a Javascript function from Code behind file.

ScriptManager.RegisterStartupScript(page, page.GetType(), key, functionNameWithBrackets + ";", true);


Also you can use with Key :

ScriptManager.RegisterStartupScript(page, page.GetType(), key, functionNameWithBrackets + ";", true);


Key value should be 'fun' for calling a function.


这篇关于如何从C#Webmethod调用Javascript方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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