如何在asp.net中的Web表单之间传递信息 [英] How to pass information between web forms in asp.net

查看:20
本文介绍了如何在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.

  1. 使用查询字符串.

源页面 - Response.Redirect("second.aspx?param=value");

目标页面 - Request.QueryString["param"].

  1. 使用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.

  1. 使用 PreviousPage 属性.注意:如果你从 first.aspx(这里只是一个例子)重定向到 second.aspx ,这适用,然后你可以使用 PreviousPage.second.aspx 中的 first.aspx 中设置的值.
  1. Use PreviousPage property. Note: This applies if you redirect from first.aspx ( just an example here), to second.aspx , then you can use PreviousPage.<propname> in second.aspx to values set in first.aspx.

second.aspx中,您需要添加这样的指令<%@ PreviousPageType VirtualPath="~/first.aspx" %>.

In second.aspx you need to add directive like this <%@ PreviousPageType VirtualPath="~/first.aspx" %>.

  1. 使用 Request.Form 读取发布的值.
  1. Use Request.Form to read posted values.

如果源页面中存在inputdropdownlist,并且您将值发布到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"].

  1. 使用 cookies 传输值.首先从 first.aspx 将一些值保存到 cookie,然后从 second.aspx 读取该值.
  1. Use cookies to transfer values. First save some value to cookie from first.aspx and read that value from second.aspx.

有关详细信息,请参阅 MSDN - MSDN 链接

Refer to MSDN for more info - MSDN link

这篇关于如何在asp.net中的Web表单之间传递信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆