webform页面传值

webform页面传值1 get 方式发送页 formid form1 runat server div ahref WebForm2 aspx name 5 调转到 Form2 ahref WebForm2 aspx name 5 div formid form1 runat server

1、get方式

发送页

 <form id="form1" runat="server"> <div> <a href="WebForm2.aspx?name=5">调转到Form2</a> <asp:Button ID="button2" Text="跳转页面" runat="server" onclick="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" onclick="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(); } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231130.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Jps算法_JPS算法

    Jps算法_JPS算法目录概念 强迫邻居(ForcedNeighbour) 跳点(JumpPoint) JPS寻路算法(JumpPointSearch) 实现原理 示例过程 JPS+(JumpPointSearchPlus) 预处理 示例过程 总结 参考概念JPS(jumppointsearch)算法实际上是对A*寻路算法的一个改进,因此在阅读本文之前需要先了解A*算法。A*算法在扩展节点时会把节点所有邻居都考虑进去,这样openlist中点的..

    2026年1月29日
    3
  • 硬件工程师成长之路(9)——检测标准

    硬件工程师成长之路(9)——检测标准系列文章目录1.元件基础2.电路设计3.PCB设计4.元件焊接6.程序设计文章目录前言一、防爆认证前言送给大学毕业后找不到奋斗方向的你(每周不定时更新)嵌入式系统设计师考试一、防爆认证详细资料………………

    2025年9月17日
    9
  • touchesBegan等方法不执行

    touchesBegan等方法不执行今天写了一个自定义控件继承于UILabel,想要在上面添加点击事件,用touchesBegan等一系列方法实现,程序跑起来自信满满,突然发现程序不执行该方法,找了半天,了解到貌似touch事件只能被UIView捕获,然后把label的用户交互开启了(发现UIImageView和UILabel的交互默认是关闭的),就能让下面的view捕获到touch事件了

    2022年7月25日
    9
  • android实现点餐功能「建议收藏」

    android实现点餐功能「建议收藏」近期项目中有点餐功能要求中午和晚上一起点餐,中午和晚上的餐品加载的都是一样的有炒菜和面点废话不多说直接上代码activity页面代码:publicclassAnimationActivityextendsBaseActivityimplementsView.OnClickListener{privateListViewrecyclerView;privateImag…

    2022年6月19日
    26
  • datax(23):dataX调优[通俗易懂]

    datax(23):dataX调优[通俗易懂]调优前需要先知道datax任务的执行过程;一、调优方向网络本身的带宽等硬件因素造成的影响;DataX本身的参数;即当觉得DataX传输速度慢时,需要从上述两个个方面着手开始排查。二、网络本身的带宽等硬件因素造成的影响此部分主要需要了解网络本身的情况,即从源端到目的端的带宽是多少(实际带宽计算公式),平时使用量和繁忙程度的情况,从而分析是否是本部分造成的速度缓慢。以下提供几个思路。1,可使用从源端到目的端scp,pythonhttp,nethogs等观察实际网络及网卡速度;2,结合.

    2022年5月13日
    141
  • Spring Boot:jar中没有主清单属性[通俗易懂]

    Spring Boot:jar中没有主清单属性[通俗易懂]使用SpringBoot微服务搭建框架,在eclipse和Idea下能正常运行,但是在打成jar包部署或者直接使用java-jar命令的时候,提示了xxxxxx.jar中没有主清单属性:D:\hu-git\spring-xxx-xxx\target>java-jarspring-cloud-eureka-0.0.1-SNAPSHOT.jarspring-xxx-xxx-0.

    2025年9月15日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号