ASP.Net WebForm JQuery 呼叫 CodeBehind方法 (手動postback)
ASP.Net WebForm JQuery 呼叫 CodeBehind方法 (手動postback)
JQuery
$('#myTextBoxB').keypress(function (e) {
if (event.which == 13) {
blockUI();
var param = '{ ' +
'"Event":"keypress", ' +
'"A":"' + $("#myTextBoxA").val() + '", ' +
'"B":"' + $("#myTextBoxB").val() + '"' +
' }';
//第1個參數 eventTarget, 第2個參數 eventArgument
__doPostBack("<%=this.myTextBoxB.ClientID%>", param);
}
});
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else
{
string eventTarget = Request.Params.Get("__EVENTTARGET");
string eventArgument = Request.Params.Get("__EVENTARGUMENT");
ParamData PData = Newtonsoft.Json.JsonConvert.DeserializeObject<ParamData>(p_EventArgument);
if (PData.Event == "keypress")
{
//處理還輯
}
}
}
public Class ParamData
{
public string Event {get; set;}
public string A {get; set;}
public string B {get; set;}
}
留言
張貼留言