在web窗体中的处理方法:
.aspx
页面代码:
<%@page language=”C#” AutoEventWireup=”true” CodeBehind=”_default.aspx.cs”
Inherits=”Exercise._default”%>
"/TR/xhtml1/DTD/xhtml1-transitional.dtd">
.aspx.cs
页面代码:
Namespce Exercise
{
Public partical class _default:System.Web.UI.Page
{
Public string name;
Public string id;
Public string sex;
Protected void Page_Load(Object Sender,EventArgs e)
{
}
}
}
1、用post()方法传递过来的值:
String name=Request.Form[“name”].ToString()==null? Request.Form[“name”].ToString()+””:
Request.Form[“name”].ToString();
2、用GET()方法传递过来的值:
String name= Request.QueryString[“name”] ==null? Request. QueryString [“name”] +””: Request.
QueryString [“name”];
3、向前台传值:
在script 脚本中用
<%=name%>来实现;
对于.ashx一般程序文件的后台接收值:
则这样写
public void ProcessRequest(HttpContext context)
{
string name = context.Request.Form["name"].ToString() == null ?
context.Request.Form["name"].ToString() + "" : context.Request.Form["name"].ToString();
string sex = context.Request.Form["sex"].ToString() == null ?
context.Request.Form["sex"].ToString() + "" : context.Request.Form["sex"].ToString(); ;
string address = context.Request.Form["address"].ToString() == null ?
context.Request.Form["address"].ToString() + "" :
context.Request.Form["address"].ToString(); ;
context.Response.ContentType = "text/plain";
context.Response.Write(Add(name,sex,address));
}
主要用到的方法为:context.Request.Form[“”].ToString();
引用必要的名称空间为:System.Web、System.Web.UI、System.Web.UI.WebControls
4、ajax、post、load方法的简单应用:
jQuery的应用方法:
$.ajax({
Type:”POST”,
url:“Exercise._default.aspx”,
data:{name:$(“#name”).val()},
content-type:”application/json;charset:utf-8”,
datatype:”json”,
success:funcation(data){
$(“#div”).html(data.d);
}
} )
$.post(
“Exercise._default.aspx”,
{name:$(“#name”).val()},
funcation(data){
$(“#div”).html(data.d);
}
)
$(“#div”).load(“Exercise._default.aspx”);