如何将值从一个页面传递到另一个页面。

编程入门 行业动态 更新时间:2024-10-24 09:17:17
本文介绍了如何将值从一个页面传递到另一个页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的, 正在使用asp C# 如何传递值一页到另一页。 我的项目有2页 在第一页我有3个文本框和一个提交按钮 在第二页我有3个标签 我输入的是什么第一页3个文本框并单击提交按钮,这3个值必须显示在第二页标签中。 请帮助如何执行此操作。 谢谢

Dear all, am working on asp C# How to pass values from one page to another page. I have 2 pages in my project In first page i have 3 textboxes and a submit button In second page i have 3 labels what ever i enter in first page 3 textboxes and click on submit button, these 3 values must display in second page labels. Please help how to do this. Thanks

推荐答案

有三种方法可以做到: 1)查询字符串:wwww .mydomain / newpage.apsx?TB1Value ='hello'&TB2Value ='再见' 2)Cookie - 这是存储在客户端上并且可以持久使用 3)会话 - 这个存储在服务器上,会话结束后会立即删除。 使用哪个取决于你:但谷歌和MSDN可以帮你判断e并向您展示如何实现它们 - 它们都非常简单! There are three ways you can do it: 1) Query string: wwww.mydomain/newpage.apsx?TB1Value='hello'&TB2Value='goodbye' 2) Cookie - this is stored on the client and can be long lasting 3) Session - this is stored on the server, and will be removed as soon as the session ends. Which to use is up to you: but Google and MSDN can help you decide and show you how to implement them - they are all very easy!

您需要使用会话变量。在第一页中,在按钮单击方法中: You need to use session variables. In the first page, in the button click method: protected void yourButton_Click(object sender, EventArgs e) { Session["txtBox1"] = yourFirstTextBox.Text; Session["txtBox2"] = yourSecondTextBox.Text; Session["txtBox3"] = yourThirdTextBox.Text; Response.Redirect("SecondPage.aspx"); }

在第二页中,将其添加到 Page_Load 方法中:

And in the second page, add this in the Page_Load method:

protected void Page_Load(object sender, EventArgs e) { if (Session["txtBox1"] != null) { yourFirstLabel.Text = (string)Session["txtBox1"]; } else { // the session value "txtBox1" is null } // do this for all labels }

有关ASP.NET会话的更多信息: 在ASP.NET中探索会话 [ ^ ]

on顶部 griff , programfox , sandeep 解决方案 另一个使用cookies的实例。 on top of griff,programfox,sandeep solution another live example using cookies. // in page1.aspx , button click HttpCookie mycookie = new HttpCookie("mycookie"); mycookie["text1"] = text1.Text; mycookie["text2"] = text2.Text; mycookie["text2"] = text3.Text; Response.Cookies.Add(mycookie); Response.Redirect("page2.aspx"); // in page2.aspx page load HttpCookie mycookie = Request.Cookies["mycookie"]; if (mycookie != null) { label1.Text = mycookie["text1"]; label2.Text = mycookie["text2"]; label3.Text = mycookie["text3"]; }

更多推荐

如何将值从一个页面传递到另一个页面。

本文发布于:2023-05-25 10:56:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!