[英]Call a web method from code behind in ascx page
我有一個腳本函數可以調用帶有兩個參數的 web 方法。我想從后面的代碼調用這個腳本函數。這是我想從后面的代碼調用的腳本函數。(我使用的是 .ascx 用戶控件)。
function BindApporment(obj, divid) {
debugger;
var username = "<%= Session["UserId"]%>";
var id = document.getElementById('<%=Hiddendocid.ClientID%>').value;
if (id != "") {
username = id;
}
$.ajax({
type: "POST",
url: "Dashboard.aspx/BindAppointment",
contentType: "application/json;charset=utf-8",
data: "{'date':'" + obj + "',userid:'" + username + "'}",
dataType: "json",
success: function (data) {
$(divid).html(data.d);
},
error: function (result) {
alert("Error ");
}
});
}
這是我的網絡方法
[WebMethod]
public static string BindAppointment(DateTime date, string userid)
{
}
...我想從后面的代碼中調用腳本函數 BindApporment() ..我已經嘗試了很多代碼,但這不起作用..我已經嘗試過這些代碼但沒有工作:
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "BindApporment", "<script>BindApporment(" + date.AddDays(k).Date + "," + ddldoc.SelectedValue + ");</script>");
有什么建議??
您正在嘗試這樣做不適用於 ASP.NET 結構中。 ascx 控件無法處理請求。 ASCX 可以處理通過 postbacl 發送的數據
您需要創建 ASMX 服務並使用您擁有的ajax
請求查詢它。 如何讓 ASMX 文件輸出 JSON
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.