<%@ WebHandler Language="C#" Class="SavePhoto" %> using System; using System.Web; using System.IO; using System.Drawing; public class SavePhoto : IHttpHandler { public void ProcessRequest(HttpContext context) { //System.Web.UI.Page page = new System.Web.UI.Page(); context.Response.ContentType = "text/plain"; if (context.Request.Form["PHeight"] != null && context.Request.Form["PWidth"] != null && context.Request.Form["strBMP"] != null) { try { int height = int.Parse(context.Request.Form["PHeight"].ToString()); int width = int.Parse(context.Request.Form["PWidth"].ToString()); string strBmp = context.Request.Form["strBMP"].ToString(); SaveBmp(BuildBitmap(width, height, strBmp), context.Server.MapPath("../../../images/CameraPhoto")); //System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); context.Response.Write("RetMsg=true"); } catch (Exception) { context.Response.Write("RetMsg=false"); } } }
我想在这里上传成功后,写提示框体,却无法实现... //System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); context.Response.Write("RetMsg=true"); 就是这样使用,只是Response.Write只是传出流的意思,没法马上执行。这个JS代码,只有服务端执行完了,传送到客服端,才会被执行 写提示框体? System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); 改成 Page.ClientScript.RegisterStartupScript(GetType(),"","<script>alert('111');</script>"); 看 int height = int.Parse(context.Request.Form["PHeight"].ToString()); int width = int.Parse(context.Request.Form["PWidth"].ToString()); string strBmp = context.Request.Form["strBMP"].ToString(); SaveBmp(BuildBitmap(width, height, strBmp), context.Server.MapPath("../../../images/CameraPhoto")); //System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); context.Response.Write("<h2 style='color:green'>保存文件成功</h2><hr />文件已经保存到服务器路径:"+ context.Server.MapPath("../../../images/CameraPhoto"));
|