How to pass information between web forms in asp.net(如何在asp.net中的Web表单之间传递信息)
问题描述
如何在asp.net中将一些信息从一个Web表单发送到另一个Web表单第一个 Web 表单是 HumanList.aspx,它在 GridView 组件中显示人员列表.当用户单击编辑链接时,我想将 humanID(人类记录 ID 的值)从 HumanList.aspx 传递到另一个名为 HumanEdit.aspx 的 Web 表单.在humanEdit.aspx 中,我想加载那个人(使用humanID)并将人类信息填充到文本框中.
how to send some information from one web form to another web form in asp.net
first web form is HumanList.aspx that shows the list of humans in a GridView component.
when user click edit link, i want to pass humanID (value of human record ID) from HumanList.aspx to another web form named HumanEdit.aspx.
In humanEdit.aspx, i want to load that human (With humanID) and fill human information into text boxes.
推荐答案
页面间传递参数的方式有很多种.
There are many ways to pass params between pages.
- 使用
查询字符串.
源页面 - Response.Redirect("second.aspx?param=value");
目标页面 - Request.QueryString["param"].
- 使用
Session.
源页面 - Session["param"] = "value"; 此处设置值.
Source page - Session["param"] = "value"; value is set here.
目标页面 - Session["param"].ToString().值在此处检索.
Destination page - Session["param"].ToString(). value is retrieved here.
- 使用
PreviousPage属性.注意:如果你从first.aspx(这里只是一个例子)重定向到second.aspx,这适用,然后你可以使用PreviousPage.到second.aspx中的first.aspx中设置的值.
- Use
PreviousPageproperty. Note: This applies if you redirect fromfirst.aspx( just an example here), tosecond.aspx, then you can usePreviousPage.<propname>insecond.aspxto values set infirst.aspx.
在second.aspx中,您需要添加这样的指令<%@ PreviousPageType VirtualPath="~/first.aspx" %>.
In second.aspx you need to add directive like this <%@ PreviousPageType VirtualPath="~/first.aspx" %>.
- 使用
Request.Form读取发布的值.
- Use
Request.Formto read posted values.
如果源页面中存在input、dropdownlist,并且您将值发布到second.aspx,那么您可以读取发布的值使用 Request.Form["input_id"].
If there are input, dropdownlist existing in source page and you are posting value to second.aspx, then you can read posted value using Request.Form["input_id"].
- 使用
cookies传输值.首先从first.aspx将一些值保存到 cookie,然后从second.aspx读取该值.
- Use
cookiesto transfer values. First save some value to cookie fromfirst.aspxand read that value fromsecond.aspx.
有关详细信息,请参阅 MSDN - MSDN 链接
Refer to MSDN for more info - MSDN link
这篇关于如何在asp.net中的Web表单之间传递信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在asp.net中的Web表单之间传递信息
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
