Html+ashx Form Submission Sample _ Practical Tips

Source: Internet
Author: User
1,sumbit form Submission

WebForm1.aspx Source:
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "NETFormDemo.ashx.WebForm1" %>

<! DOCTYPE html>

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script type= "Text/javascript" >

</script>
<body>
<form id= "Form1" action= "Submitform.ashx" >
<div>
<input type= "Submit" value= "submitted"/>
</div>
</form>
</body>

Submitform.ashx Source:
Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;

Namespace Netformdemo.ashx
{
<summary>
Summary description of 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 Submit
Htmlpage1.html Source:
Copy Code code as follows:

<! DOCTYPE html>


<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>

<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>


Add.ashx Source:
Copy Code code as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

Namespace Netformdemo.ashx
{
///<summary>
///Login Summary description
///</summary>
public class Login:ihttphandler
{

public void ProcessRequest (HttpContext context)
{
Co ntext. Response.ContentType = "Text/plain";
Int-A-convert.toint32 (context. request.params["I"]);
Int sec = Convert.ToInt32 (context. Request.params["J"]);

Int res = the i + sec;
Context. Response.Write (RES);
Context. Response.Write ("FDD ff");

}

public bool isreusable
{
Get
{
return false;
}
}


}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.