.aspx使用方式
1. 重新執行db指令
2. viewstate
3. session
Session["tempDT"] = oldTable; //存放 DataTable newTable = (DataTable)Session["tempDT"]; //取出 |
4. Cookie
.ashx使用方式
using System.Web.SessionState; public class Handler : IHttpHandler, IRequiresSessionState{ public void ProcessRequest(HttpContext context) context.Session["tempDT"] = oldTable; //存放 DataTable newTable = (DataTable)context.Session["tempDT"]; //取出 } } public bool IsReusable |
另外一種是在前端使用ScriptManager,並將EnablePageMethods屬性設為True。
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
前端調用後端
<script>
$(function () { // var a = "<%=ss()%>";
PageMethods.callServer("1213", onCallSucceeded);
});
function onCallSucceeded(result)
{
console.log(result);
}
</script>
後端
[WebMethod]//標示為web服務方法屬性
public static string callServer(string query)//注意函式的修飾符,只能是靜態的
{
string newString= "I'm server";
return newString;
}