第十节 8ASP.Net揭秘之Input版自增补充说明
<%@ WebHandler Language="C#" Class="IntValue2" %> using System; using System.Web; public class IntValue2 : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; context.Response.Write("Hello World"); string ispostback = context.Request["ispostback"]; string number = context.Request["number"]; string issubmit = context.Request["issubmit"]; if (ispostback == "true") { int i = Convert.ToInt32(number); if (issubmit == "1") { i++; } else { if (i > 1) { i--; } } number = i.ToString(); }else{ number = "0"; } string filepath = context.Server.MapPath("IntValue2.htm"); string content = System.IO.File.ReadAllText(filepath); content = content.Replace("@number",number); content = content.Replace("@issubmit",issubmit); context.Response.Write(content); } public bool IsReusable { get { return false; } } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script language="javascript"> function SetIsSubmit(val) { //alert("val=="+val); $("#issubmit").val(val); //alert($("#issubmit").val()); } </script> <form method="post" action="IntValue2.ashx"> <input type="hidden" name="ispostback" value="true" /> <input type="hidden" name="issubmit" id="issubmit" value="@issubmit" /> <input type="text" name="number" value="@number"/> <input type="submit" name="submit" value="自增" onclick="SetIsSubmit(1)"/> <input type="submit" name="submit2" value="自减" onclick="SetIsSubmit(2)"/> </form> </body> </html>