Using JS to invoke the background write method
1<script src="Js/jquery-1.7.1.min.js"></script>2 2<script>3 3$ (function () {4 4$(". BTN"). Click (function () {5 5$("#txtname"). Val ('<%=session["Name"]%>');6 6$("#txtdate"). Val ('<%=getdate ()%>');7 7$("#txtnum"). Val ('<%=getnum ()%>');8 8 });9 9 });Ten Ten</script> One One A A - - - - the the<body> - -<form id="Form1"runat="Server"> - -<div> - -<asp:textbox id="txtname"runat="Server"></asp:textbox><br/> + +<asp:textbox id="txtdate"runat="Server"></asp:textbox><br/> - -<asp:textbox id="Txtnum"runat="Server"></asp:TextBox> + +<input type="Button" class="btn"Value="Submit"/> A A</div> at at</form> - -</body>
Front Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8 namespaceTest9 {Ten Public Partial classForeground Call backstage method: System.Web.UI.Page One { A protected voidPage_Load (Objectsender, EventArgs e) - { -session["Name"] ="Dawn"; the } - Public Static stringGetnum () - { - stringnum ="Zhang San"; + returnnum; - } + Public stringGetDate () A { at stringDate = System.DateTime.Now.ToString ("YYYY-MM-DD"); - returndate; - } - } -}
Background Code
Calling the background method in an ASP. JQuery Event