---------------------- <a target="blank">ASP.Net+Android+IO开发S</a>、<a target="blank">.Net培训</a>、期待与您交流! ----------------------
<%@ WebHandler Language="C#" Class="C06Cul" %>
using System;
using System.Web;
using System.Text;
public class C06Cul : IHttpHandler {
public void ProcessRequest (HttpContext context) {
StringBuilder sbHTML = new StringBuilder();
string strNum1 = context.Request.Form["txtNum1"];
string strNum2 = context.Request.Form["txtNum2"];
int x = 0;
int y = 0;
int z = 0;
//如果包含隐藏域的话,才执行相加运算操作
if (!string.IsNullOrEmpty(context.Request.Form["hidIsPostBack"]))
{
if (!string.IsNullOrEmpty(strNum1) && !string.IsNullOrEmpty(strNum2))
{
if (int.TryParse(strNum1, out x) && int.TryParse(strNum2, out y))
{
z = x + y;
}
}
}
sbHTML.Append("<html><head><title>计算器</title></head><body><form action='' method='post'>");
sbHTML.Append("<input type='text' name='txtNum1' value='" + x.ToString() + "'/> + <input type='text' name='txtNum2' value='" + y.ToString() + "'/> = <input type='text' name='txtSum' value='" + z.ToString() + "'/><br/>");
sbHTML.Append("<input type='submit' value='计算'/>");
sbHTML.Append("<input type='hidden' name='hidIsPostBack' value='1'/></form></body></html>");
context.Response.Write(sbHTML.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------- <a target="blank">ASP.Net+Android+IOS开发</a>、<a target="blank">.Net培训</a>、期待与您交流! ----------------------
|
|