页面传参的几种方式

页面之间传值的几种方法

1.Get方式

发送页代码:Response.Redirect("WebFormA2.aspx?name=" + TextBox1.Text);

接收页代码:

this.TextBox1.Text = Request["name"];
            //this.TextBox1.Text=Request.Params["name"];
            //this.TextBox1.Text=Request.QueryString["name"];

2.使用内存变量

发送页代码:

Session["name"] = this.TextBox1.Text;
            //Application["name"]=this.TextBox1.Text;

接收页代码:

this.TextBox1.Text = (string)Session["name"];
          //this.TextBox1.Text = (string)Application["name"];

3.Post方式

     发送页代码:

<form id="form1" runat="server" action="WebFormC2.aspx" method="post">
                 <input name="txtname" type="text" value="Andy"/>
                 <input type="submit" value="提交到WebFormC2.aspx"/>   
        </form>

接收页代码:

if (Request.Form["txtname"] != null)
            {
                TextBox1.Text = Request.Form["txtname"];
            }

注意:<form>中不能带runat="server".否则不起作用.

            <form>中的mothod="post"

4.静态变量

         发送页代码:

//定义一个公共变量
                 public static string str = "";
                 protected void Button1_Click(object sender, EventArgs e)
                {
                     str = this.TextBox1.Text;
                     Response.Redirect("WebFormD2.aspx");
                 }

接收页代码:  this.TextBox1.Text = WebFormD1.str;

5.Context.Handler获取控件

        发送页代码:

<asp:TextBox ID="TextBox1" Text="Andy" runat="server"></asp:TextBox>
               <asp:Button ID="Button1" runat="server" Text="进入WebFormE2.aspx" OnClick="Button1_Click" />

//Button1_Click事件代码

Response.Redirect("WebFormE2.aspx");

接收页面代码:

//获取post过来的页面对象
            if (Context.Handler is WebFormE1)
            {
                //取得页面对象
                WebFormE1 poster = (WebFormE1)Context.Handler;

//取得控件               
                this.TextBox1.Text = ((TextBox)poster.FindControl("TextBox1")).Text;
                //this.TextBox1.Text = poster.TextBox1.Text;
            }

6.Context.Handler获取公共变量

        发送页代码:

//定义一个公共变量
             public string strname = "Andy";
             protected void Button1_Click(object sender, EventArgs e)
            {            
                 Response.Redirect("WebFormE2.aspx");

}

接收页代码:

//获取post过来的页面对象
            if (Context.Handler is WebFormF1)
            {
                //取得页面对象
                WebFormF1 poster = (WebFormF1)Context.Handler;
                this.TextBox1.Text = poster.strname;
            }

7.Context.items变量

     发送页代码:

protected void Button1_Click(object sender, EventArgs e)
            {
                  Context.Items["name"] = TextBox1.Text;
                  Server.Transfer("WebFormG2.aspx");
             }

接收页代码:

//获取post过来的页面对象
            if (Context.Handler is WebFormG1)
            {
                this.TextBox1.Text = Context.Items["name"].ToString();
            }

时间: 2024-08-24 02:41:39

页面传参的几种方式的相关文章

3.struts2接收页面传参的三种方式

Struts2通过拦截器机制封装了三种接收页面参数的方式: 1.属性驱动 2.模型驱动(有两种) Domain ModelDriven 1.属性驱动:这种方式比较简单,只要你直接在页面定义变量并且符合以下两个规则,就会自动接收值. 规则1:你变量的名字和页面的name属性一致 规则2:生成对应的get set方式 Action写法: public class ParamAction { private String username; private String password; publi

Vue路由传参的几种方式

原 Vue路由传参的几种方式 2018年07月28日 23:52:40 广积粮缓称王 阅读数 12613 前言:顾名思义,vue路由传参是指嵌套路由时父路由向子路由传递参数,否则操作无效.传参方式可以划分为params传参和query传参,params传参又可以分为url中显示参数和不显示参数两种方式.具体区分和使用后续分析. 参考官网:https://router.vuejs.org/zh/guide/essentials/navigation.html params传参(url中显示参数)

senchaTouch 给组件传参的两种方式

在senchaTouch 页面跳转中,有时我们需要将其前一个页面的相关参数传入到新的页面或者新的控件中,这是我们该如何传递参数进去呢,一下有两种方式: var arg;//定义将要 传入的参数 Ext.define('MyApp.view.Init',{ extend:'Ext.Container', id:'chat_more_btm', xtype:'init', config:{ layout:'fit', myarg:arg//把将要传入的参数映射到一个属性上面 }, initializ

传参的两种方式

SQL语句的执行不可缺少参数的传递,传递参数直接拼接SQL语句不可避免会遇到SQL注入问题,会造成很严重的系统安全问题,所以一般会使用 SetParameterValue("@abc", abc),拼接一个可变的参数集合parms ,在SQl语句中使用如下 <dataCommand name="SubmitProductEntryAudit" database="Write" commandType="Text">

SpringBoot整合Mybatis传参的几种方式

转自https://blog.csdn.net/irelia_/article/details/82347564 在SpringBoot整合Mybatis中,传递多个参数的方式和Spring整合Mybatis略微有点不同,下面主要总结三种常用的方式 一.顺序传参法 Mapper层: 传入需要的参数 public interface GoodsMapper { public Goods selectBy(String name,int num); }1234Mapper.xml: *使用这种方式,

mybatis传参的几种方式

1,@Param @参考文章 @Select("select s_id id,s_name name,class_id classid from student where  s_name= #{aaaa} and class_id = #{bbbb}")  public Student select(@Param("aaaa") String name,@Param("bbbb")int class_id); @Select(....)注解的作

vue 路由跳转,路由传参的几种方式

1. router-link <router-link :to="{ path: 'yourPath', params: { name: 'name', dataObj: data }, query: { name: 'name', dataObj: data } }"> </router-link> 2. $router方式跳转 this.$router.push({ path: 'yourPath', query: { name: 'name', dataO

HttpClient 调用WebAPI时,传参的三种方式

public void Post() { //方法一,传json参数 var d = new { username = " ", password = " ", grant_type = "password", appcode = " ", companyid = " ", version = "1.0", }; var data = JsonConvert.SerializeObjec

thinkphp 3.2.3 入门示例2(URL传参数的几种方式)

原文:thinkphp中URL传参数的几种方式 在thinkphp中,url传参合asp.net中原理类似,下面就单个参数和多个参数传递方式进行一个简单讲解 1.传单个参数 单个参数这种比较简单,例如 想像edit操作里面传递一个id值,如下写法__URL__/edit/id/1 http://localhost/index.php/user/edit/id/1 id和其值1要分别位于/后面 后台获取id通过    $id=$_GET['id']   即可获取其具体值. 2.传多个参数 传多个参