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表单之间传递信息
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
