我怎樣才能從客戶端調用代碼隱藏功能?來自jquery的函數調用代碼方
// Code-behind function:
public void CodeBehindFunction(int i)
{
...
}
我想從客戶端調用它...
// Client-side call:
$(this). ??
我怎樣才能從客戶端調用代碼隱藏功能?來自jquery的函數調用代碼方
// Code-behind function:
public void CodeBehindFunction(int i)
{
...
}
我想從客戶端調用它...
// Client-side call:
$(this). ??
正確你的意思是你要撥打的客戶端代碼服務器端程序...
我建議你強制使用JavaScript回發:__doPostback('CodeBehindFunction',iParameter);
- 然後在你的服務器端代碼的頁面初始化事件中,通過類似的方式來捕獲此自定義回發。
if (Request.Params["__EVENTTARGET"] == "CodeBehindFunction")
{
int i;
// Try to convert the argument (in the example this is the value of iParameter)
if (int.TryParse(Request.Params("__EVENTARGUMENT"),out i)
{
CodeBehindFunction(i);
}
}
或者使用通過jQuery.ajax調用的WebService。
您可以使用Ajax調用CodeBehindFunction(int i)以 ,但你必須標記方法的WebMethod和靜態:
[WebMethod]
public static void CodeBehindFunction(int i)
{
...
}
然後從JS
$.ajax({
type: "POST",
url: "/yourPage.aspx/CodeBehindFunction",
data: "{'i':'"+num+"'}", //PUT DATA HERE
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
}
})
稱之爲** yourPage .aspx是聲明CodeBehindFunction方法的頁面
我建議您提供一些代碼並以其他方式展開您的問題,否則您會得到一些-1s來自您的方式... –