1.在webfrom页面的AJAX传值
页面:
function SaveItemCraft(id) {
var NewValue = $("#TextItemCraft_" + id).val();
$.ajax({
url: ("FinancialCenter.aspx?timestamp={0}").format(new Date().getTime()),
type: 'POST', dataType: 'json', timeout: 10000,
data: { Action: "UpdateItemCraft", Callback: "true", ItemId: id, UpdateValue: NewValue },
success: function (resultData) {
if (resultData.STATUS == "SUCCESS") {
$("#ItemCraft_" + id).text(NewValue);
$("#imgItemCraft_" + id).show();
$("#TextItemCraft_" + id).hide();
$("#aItemCraft_" + id).hide();
$("#aItemCraft2_" + id).hide();
$("#ItemCraft_" + id).show();
}
else {
alert("系统忙请稍后再试!");
}
}
});
}
后台:
using Jayrock.Json;
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(base.Request.Form["Callback"]) && (base.Request.Form["Callback"] == "true"))
{
this.Controls.Clear();
this.DoCallback();
}
if (!this.Page.IsPostBack)
{
。。。。
}
}
private void DoCallback()
{
string action = base.Request.Form["Action"];
base.Response.Clear();
base.Response.ContentType = "application/json";
string s = string.Empty;
if (action != null)
{
switch (action)
{
case "UpdateItemCraft":
s = this.UpdateItemCraft();
break;
}
}
base.Response.Write(s);
base.Response.End();
}
private string UpdateItemCraft()
{
JsonObject obj2 = new JsonObject();
long itemId = Globals.SafeLong(base.Request.Form["itemId"], (long)0L);
string newValue = Globals.SafeString(base.Request.Params["UpdateValue"], "");
if (orderBll.UpdateCostPrice(itemId, decimal.Parse(newValue)))
{
obj2.Put("STATUS", "SUCCESS");
}
else
{
obj2.Put("STATUS", "FAILED");
}
return obj2.ToString();
}