您好,欢迎来到欧得旅游网。
搜索
您的当前位置:首页前台后台传送和接收值的方法

前台后台传送和接收值的方法

来源:欧得旅游网
在web窗体中的处理方法:

.aspx

页面代码:

<%@page language=”C#” AutoEventWireup=”true” CodeBehind=”_default.aspx.cs” Inherits=”Exercise._default”%>

.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.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”,

System.Web.UI、

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”);

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- ovod.cn 版权所有 湘ICP备2023023988号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务