html+ashx 表单提交示例
更新时间:2021年9月22日 10:12 点击:1533
1,sumbit表单提交
WebForm1.aspx源码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NETFormDemo.ashx.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
</script>
</head>
<body>
<form id="form1" action="submitForm.ashx" >
<div>
<input type="submit" value="提交" />
</div>
</form>
</body>
</html>
submitForm.ashx源码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NETFormDemo.ashx
{
/// <summary>
/// submitForm 的摘要说明
/// </summary>
public class submitForm : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
2,ajax提交
HtmlPage1.html 源码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="test1.js" type="text/javascript"></script>
<script src="jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function add(url) {
var A = $("#a1").val();
var B = $("#b1").val();
$.ajax({
url: "ashx/add.ashx?i=" + A + "&j=" + B,
data: {
num1: A,
num2: B
},
dataType: "html",
success: function (result) {
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="a1" />
<input type="text" id="b1"/>
<input type="button" onclick="add()"/>
<label id="lb"></label>
</form>
</body>
</html>
add.ashx源码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NETFormDemo.ashx
{
/// <summary>
/// Login 的摘要说明
/// </summary>
public class Login : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int first = Convert.ToInt32(context.Request.Params["i"]);
int sec = Convert.ToInt32(context.Request.Params["j"]);
int res = first + sec;
context.Response.Write(res);
context.Response.Write("fdd ff");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
WebForm1.aspx源码:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NETFormDemo.ashx.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
</script>
</head>
<body>
<form id="form1" action="submitForm.ashx" >
<div>
<input type="submit" value="提交" />
</div>
</form>
</body>
</html>
submitForm.ashx源码:
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NETFormDemo.ashx
{
/// <summary>
/// submitForm 的摘要说明
/// </summary>
public class submitForm : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
2,ajax提交
HtmlPage1.html 源码:
复制代码 代码如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="test1.js" type="text/javascript"></script>
<script src="jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function add(url) {
var A = $("#a1").val();
var B = $("#b1").val();
$.ajax({
url: "ashx/add.ashx?i=" + A + "&j=" + B,
data: {
num1: A,
num2: B
},
dataType: "html",
success: function (result) {
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="a1" />
<input type="text" id="b1"/>
<input type="button" onclick="add()"/>
<label id="lb"></label>
</form>
</body>
</html>
add.ashx源码:
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NETFormDemo.ashx
{
/// <summary>
/// Login 的摘要说明
/// </summary>
public class Login : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int first = Convert.ToInt32(context.Request.Params["i"]);
int sec = Convert.ToInt32(context.Request.Params["j"]);
int res = first + sec;
context.Response.Write(res);
context.Response.Write("fdd ff");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
上一篇: 上传图片后使用数据库保存图片的示例分享
下一篇: C#默认以管理员身份运行程序实现代码
相关文章
- 获取ashx得到的内容,一般用于ajax的情况比较多一点;重点:ashx页面传过来的就是已经处理好的数据,感兴趣的朋有可以参考下啊,希望本文对你学习ajax有所帮助...2021-09-22
- 本文主要介绍在Session存储唯一标识Token,通过和后台对比,以实现防止刷新提交表单的问题。...2021-09-22
asp.net中js和jquery调用ashx的不同方法分享
asp.net中js和jquery调用ashx的不同方法分享,需要的朋友可以参考一下...2021-09-22ASP.NET:把ashx写到类库里并在页面上调用的具体方法
最近在调整博客的架构,进一步把表现和业务分离,所以要把之前用ashx搞的那些Http Handler放到类库中,下面是具体的步骤及代码...2021-09-22- 一般处理程序(HttpHandler):是一个实现System.Web.IHttpHandler接口的特殊类。任何一个实现了IHttpHandler接口的类是作为一个外部请求的目标程序的前提,感兴趣的朋友可以了解下或许有所帮助...2021-09-22
- <?php include("../inc/inc.php"); islogin(); $Db = new Db(); //此数据库类地址数据库连接类 ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//...2016-11-25
- 这篇文章主要是对ashx文件的使用进行了介绍。需要的朋友可以过来参考下,希望对大家有所帮助...2021-09-22
- .ashx文件中获取cookies值对于一些高手们就不多说了,至于一些小白们还是有必要多多学习啊,好了话不多说,看代码,感兴趣的你可不要错过了哈...2021-09-22
Asp.net webForm设置允许表单提交Html的方法
下面小编就为大家分享一篇Asp.net webForm设置允许表单提交Html的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-09-22- 这篇文章主要介绍了asp.net利用ashx文件实现文件的上传功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22
- 这篇文章主要介绍了mvc form表单提交的几种形式整理总结的相关资料,这里提供了几种方法及实例代码,需要的朋友可以参考下...2021-09-22
基于.NET中:自动将请求参数绑定到ASPX、ASHX和MVC的方法(菜鸟必看)
这篇文章的目的就是告诉初学者如何自动将客户端用AJAX发送的参数自动绑定为强类型的成员属性或方法参数...2021-09-22- 分页思路: .ashx程序中,编写好取得不同页码的程序。在页面布局好的前提下,留下数据区域 div。然后在页面请求 .ashx程序生成下一页的html代码。覆盖div.innerHTMl...2021-09-22
- 这篇文章主要为大家详细介绍了ASP.NET ashx实现无刷新页面生成验证码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
- 有时候需要在ASHX中获取Session,可是一般是获取不到的,如何解决,下面说一下获得的方法...2021-09-22
- 这篇文章介绍了php中表单提交时去除斜杠的教程,初学时经常会有这样的疑问,希望能帮助到有需要的同学 本文实例讲述了PHP实现表单提交时去除斜杠的方法。分享给大家...2016-12-31
Asp.net在ashx文件中处理Session问题解决方法
Asp.net在ashx文件中处理Session问题解决方法,需要的朋友可以参考一下...2021-09-22- 其实扩展名为ashx与为axd基本上是一样的,都是用于写web handler,可以通过它来调用IHttpHandler类,它免去了普通.aspx页面的控件解析以及页面处理的过程。...2021-09-22
- 数据丢失对于小编来讲是个头痛的问题了,因为小编碰到表单提交大量数据发生丢失问题也是这几天了,但不是时尚而有时会丢失了,这个问题非常难解决,下面整理了一些解决办法,希...2016-11-25
- 这篇文章主要介绍了*.ashx文件不能访问Session值的解决方法,只需在头部引用一个命名空间即可解决问题,非常实用,需要的朋友可以参考下...2021-09-22