[英]Unable To Keep Textbox Value When Asp.net File Upload On change event call?
[英]How to call web method on change event of textbox in asp.net
我有一個文本框。 在輸入時,我想像粘貼一樣保存其數據。注意,我的意思是asp.net中的“自動保存”文本框。
我的前端代碼是:
<textarea id="txtClientArea" runat="server" class="scfMultipleLineTextBox" cols="20" rows="4" onchange="onTextChange" >
我的javascript網絡方法是:
function onTextChange(data) {
debugger;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "StickyNote.aspx/SaveData",
data: JSON.stringify({ "data": data }),
datatype: "json",
async: false,
success: function (response) {
alert("C# method calling : " + response.d);
},
error: function (err) {
alert(err.responseText);
}
});
}
方法后面的代碼是:
[System.Web.Services.WebMethod]
public static void SaveData(string data)
{
User currentUser = Sitecore.Context.User;
if (currentUser != null)
{
currentUser.Profile.SetCustomProperty("StickyNote", data);
}
}
如何使文本框數據自動保存?
您可以嘗試以下方法:
$('#<%=txtClientArea.ClientID%>').on('change',function () {
var data = encodeURIComponent($(this).text());
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "StickyNote.aspx/SaveData",
data: JSON.stringify({ "data": data }),
datatype: "json",
async: false,
success: function (response) {
alert("C# method calling : " + response.d);
},
error: function (err) {
alert(err.responseText);
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.