日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

.net通过一般处理程序模拟用户控件数据保持、Ispostback 【第二版将html与ashx文件分开】...

發(fā)布時間:2025/4/5 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net通过一般处理程序模拟用户控件数据保持、Ispostback 【第二版将html与ashx文件分开】... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

直接上代碼:

HTML代碼,其中表單中input標簽中的value值首先用一個占位符占位,然后在ashx中將其替換

<html xmlns="http://www.w3.org/1999/xhtml"> <head><title></title> </head> <body> <form action = "02jsqHandler.ashx" method = "post"><input type = "text" name = "txtNum1" value = "@txtNum1" />+<input type = "text" name = "txtNum2" value = "@txtNum2" />=<input type = "text" name = "txtResult" value = "@txtResult" /><input type = "hidden" name = "IsPostBack" value = "false" /><input type = "submit" value = "計算" /> </form> </body> </html>

ashx代碼:

首先用io中的File.ReadAllText()方法將html文件讀出來

public class _02jsqHandler : IHttpHandler {public void ProcessRequest (HttpContext context) {context.Response.ContentType = "text/html";//獲得html文件的內容string path = context.Server.MapPath("03jsq2.htm");string strHtml = File.ReadAllText(path);//聲明三個整形變量int n1 = 0, n2 = 0, result = 0;bool ispostback = Convert.ToBoolean(context.Request.Form["IsPostBack"]);if (!ispostback) //判斷是否是第一次加載相當于aspx.cs中的IsPostBack {//分別獲得數1和數2string sn1 = context.Request.Form["txtNum1"];string sn2 = context.Request.Form["txtNum2"];if (int.TryParse(sn1, out n1) && int.TryParse(sn2, out n2)){result = n1 + n2;}//context.Response.Write(result.ToString()); }//將html中的@參數(占位符替換為對應的數據)strHtml = strHtml.Replace("@txtNum1", n1.ToString()).Replace("@txtNum2", n2.ToString()).Replace("@txtResult", result.ToString());//將html寫回頁面 context.Response.Write(strHtml);}public bool IsReusable {get {return false;}}

?

轉載于:https://www.cnblogs.com/wlitsoft/archive/2012/04/20/2460603.html

總結

以上是生活随笔為你收集整理的.net通过一般处理程序模拟用户控件数据保持、Ispostback 【第二版将html与ashx文件分开】...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。