webform页面传值

2024-02-02 08:08
文章标签 页面 传值 webform

本文主要是介绍webform页面传值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、get方式

发送页

<form id="form1" runat="server"><div><a href="WebForm2.aspx?name=5">调转到Form2</a><asp:Button ID="button2" Text="跳转页面" runat="server" οnclick="button2_Click"/></div>
</form>protected void button2_Click(object sender, EventArgs e)
{Response.Redirect("WebForm2.aspx?name=5");
}

接受页

this.Label1.Text = Request["name"];
//this.Label2.Text = Request.Params["name"];
//this.Label3.Text = Request.QueryString[0];

2、post方式

a\不带 runat="server"形式

发送页

<form id="form2" action="WebForm2.aspx" method="post"><input name="txtname" type="text" value="lilili"  /><input type="submit" value="提交网页" />
</form>

接受页

this.Label1.Text =Request.Form["txtname"];

b\带 runat=“server”

发送页

<form runat="server" id="form3"><input id="btnTransfer" type="button" onclick="post();" runat="server" value="跳转" /> 
</form>
<form id="form4" method="post"><input type="text" runat="server" id="txtname" value="lili" />
</form>
<script type="text/javascript">function post() {form4.action = "WebForm2.aspx";form4.submit();}
</script>

接受页

this.Label1.Text =Request.Form["txtname"];

3、Session 和 Application

Session["name2"] = "sessontest";
Application["name3"] = "applicationtest";this.Label2.Text =(string)Session["name2"];
this.Label3.Text =(string)Application["name3"];

4、静态变量

发送页

public static string statest="static string";
protected void button2_Click(object sender, EventArgs e)
{Server.Transfer("WebForm2.aspx");
}

接受页

this.Label1.Text = WebForm1.statest;

5、Context.Handler 获取控件

发送页

<asp:TextBox ID="TextBox1" runat="server" Text="lilili"></asp:TextBox>
<asp:Button ID="button2" Text="跳转页面" runat="server" οnclick="button2_Click"/>protected void button2_Click(object sender, EventArgs e)
{Server.Transfer("WebForm2.aspx");
}

接受页

//获取post传过来的对象
if (Context.Handler is WebForm1)
{WebForm1 poster = (WebForm1)Context.Handler;this.Label1.Text = ((TextBox)poster.FindControl("TextBox1")).Text;
}

6、Context.Handler 获取公共变量

发送页

public string testpost = "testpost";
protected void button2_Click(object sender, EventArgs e)
{Server.Transfer("WebForm2.aspx");
}

接受页

//获取post传过来的对象
if (Context.Handler is WebForm1)
{WebForm1 poster = (WebForm1)Context.Handler;this.Label2.Text = poster.testpost;}

7、Context.Items 变量

发送页

protected void button2_Click(object sender, EventArgs e)
{Context.Items["name"] = "contextItems";Server.Transfer("WebForm2.aspx");
}

接受页

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

这篇关于webform页面传值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/670034

相关文章

禁止HTML页面滚动的操作方法

《禁止HTML页面滚动的操作方法》:本文主要介绍了三种禁止HTML页面滚动的方法:通过CSS的overflow属性、使用JavaScript的滚动事件监听器以及使用CSS的position:fixed属性,每种方法都有其适用场景和优缺点,详细内容请阅读本文,希望能对你有所帮助... 在前端开发中,禁止htm

Java多线程父线程向子线程传值问题及解决

《Java多线程父线程向子线程传值问题及解决》文章总结了5种解决父子之间数据传递困扰的解决方案,包括ThreadLocal+TaskDecorator、UserUtils、CustomTaskDeco... 目录1 背景2 ThreadLocal+TaskDecorator3 RequestContextH

SpringMVC前后端传值的几种实现方式

《SpringMVC前后端传值的几种实现方式》本文主要介绍了SpringMVC前后端传值的方式实现,包括使用HttpServletRequest、HttpSession、Model和ModelAndV... 目录一、从Controller层到JSP界面1、使用HttpServletRequest的方式2、使

使用JavaScript将PDF页面中的标注扁平化的操作指南

《使用JavaScript将PDF页面中的标注扁平化的操作指南》扁平化(flatten)操作可以将标注作为矢量图形包含在PDF页面的内容中,使其不可编辑,DynamsoftDocumentViewer... 目录使用Dynamsoft Document Viewer打开一个PDF文件并启用标注添加功能扁平化

SpringBoot如何访问jsp页面

《SpringBoot如何访问jsp页面》本文介绍了如何在SpringBoot项目中进行Web开发,包括创建项目、配置文件、添加依赖、控制层修改、测试效果以及在IDEA中进行配置的详细步骤... 目录SpringBoot如何访问JSP页python面简介实现步骤1. 首先创建的项目一定要是web项目2. 在

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

Weex入门教程之3,使用 Vue 开发 Weex 页面

环境安装 在这里简略地介绍下,详细看官方教程 Node.js 环境 Node.js官网 通常,安装了 Node.js 环境,npm 包管理工具也随之安装了。因此,直接使用 npm 来安装 weex-toolkit。 npm 是一个 JavaScript 包管理工具,它可以让开发者轻松共享和重用代码。Weex 很多依赖来自社区,同样,Weex 也将很多工具发布到社区方便开发者使用。

16 子组件和父组件之间传值

划重点 子组件 / 父组件 定义组件中:props 的使用组件中:data 的使用(有 return 返回值) ; 区别:Vue中的data (没有返回值);组件方法中 emit 的使用:emit:英文原意是:触发、发射 的意思components :直接在Vue的方法中声明和绑定要使用的组件 小炒肉:温馨可口 <!DOCTYPE html><html lang="en"><head><

React 笔记 父子组件传值 | 父组件调用子组件数据 | defaultProps | propsType合法性验证

1.通过props实现父组件像子组件传值 、方法、甚至整个父组件 传递整个父组件则   [变量名]={this} import Header from "./Header"render(){return(<Header msg={"我是props传递的数据"}/>)} import React,{Component} from "react";class Header extends

react笔记 8-18 事件 方法 定义方法 获取/改变数据 传值

1、定义方法并绑定 class News extends React.Component {constructor(props) {super(props)this.state = {msg:'home组件'}}run(){alert("我是一个run") //方法写在类中}render() {return (<div><h2>{this.state.msg}</h2><button onCli