有什么方法可以使用javascript调用服务器端事件? [英] is there any way to call the serverside events using javascripts?
本文介绍了有什么方法可以使用javascript调用服务器端事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我曾经尝试过使用Pagemethods.Method1
但是对我来说,我需要调用一个服务器端事件,例如)
Hi, I have alrady tried with the Pagemethods.Method1
But for me, i need to call an serverside event eg)
function myFunction() {
PageMethods.Method1();
}
public static void Method1()
{
class clss1 = new class()
class1.txtBox1_TextChanged(new object(), new EventArgs());
}
protected void txtBox1_TextChanged(object sender, EventArgs e)
{
Label1.Text = "";
panel1.Visible = true;
}
在这里,txtBox1_TextChanged()
被触发,但是页面控件的值始终为null.
请帮助我解决此问题.
在此先感谢.
Here, txtBox1_TextChanged()
is getting triggred but the values of the page controls are always getting as null.
Please help me to solve this issue.
Thanks in advance.
推荐答案
将[System.Web.Services.WebMethod()]
添加到您的代码中,就像这样
add[System.Web.Services.WebMethod()]
to your code like this
[System.Web.Services.WebMethod()]
public static void Method1()
{
class clss1 = new class()
class1.txtBox1_TextChanged(new object(), new EventArgs());
}
或使用jquery ajax
方法
or use jquery ajax
method
.ajax({ 类型:" , contentType:" , 网址:" , 数据:" , dataType:" , 成功:功能(数据){ // 写入功能以显示数据 }, 错误:函数(结果){ alert(" ); } });
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "yourpage.aspx/yourmethod", data: "{}", dataType: "json", success: function(data) { //Write functionality to display data }, error: function(result) { alert("Error"); } });
More info from here and here
这篇关于有什么方法可以使用javascript调用服务器端事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文