1如何判断是提交进入还是直接进入
2使用模板机制在ashx输入html文件中内容
3占位符的控制,使本本框内容在提交以后保持
ASP中的代码:
<formaction="Once.ashx"method="get">
<inputtype="hidden"name="isNullText"value="true"/>
<inputtype="text"name="price"value="0"/>
<inputtype="submit"value="提交"/>
</form>
ashx输入html文件中内容:
publicclassOnce:IHttpHandler{
publicvoidProcessRequest(HttpContextcontext){
context.Response.ContentType="textml";
stringnum=context.Request["price"];//获得文本框的value值
stringisNullText=context.Request["isNullText"];//得到表单的value值。"true"
if(isNullText=="true")//如果相等是提交进来的并将将文本框里面的值加1,否则将文本里面的值负值为0
{
context.Response.Write("提交进入!");
num=(int.Parse(num)+1).ToString();
}
else
{
context.Response.Write("直接进入!");
num="0";
}
stringfullPath=context.Server.MapPath("index.htm");//获得html的路径将它给一个变量
stringhtmlContext=System.IO.File.ReadAllText(fullPath);//将这个路径负值给一个变量
htmlContext=htmlContext.Replace("0",num);//将文本框原有的值替换为改变后的数
context.Response.Write(htmlContext);//将整个html输出
context.Response.Write("HelloWorld");
}
2使用模板机制在ashx输入html文件中内容
3占位符的控制,使本本框内容在提交以后保持
ASP中的代码:
<formaction="Once.ashx"method="get">
<inputtype="hidden"name="isNullText"value="true"/>
<inputtype="text"name="price"value="0"/>
<inputtype="submit"value="提交"/>
</form>
ashx输入html文件中内容:
publicclassOnce:IHttpHandler{
publicvoidProcessRequest(HttpContextcontext){
context.Response.ContentType="textml";
stringnum=context.Request["price"];//获得文本框的value值
stringisNullText=context.Request["isNullText"];//得到表单的value值。"true"
if(isNullText=="true")//如果相等是提交进来的并将将文本框里面的值加1,否则将文本里面的值负值为0
{
context.Response.Write("提交进入!");
num=(int.Parse(num)+1).ToString();
}
else
{
context.Response.Write("直接进入!");
num="0";
}
stringfullPath=context.Server.MapPath("index.htm");//获得html的路径将它给一个变量
stringhtmlContext=System.IO.File.ReadAllText(fullPath);//将这个路径负值给一个变量
htmlContext=htmlContext.Replace("0",num);//将文本框原有的值替换为改变后的数
context.Response.Write(htmlContext);//将整个html输出
context.Response.Write("HelloWorld");
}