ASP.Net:PreviousPage与Content页面有关 [英] ASP.Net : PreviousPage issues with Content page

查看:71
本文介绍了ASP.Net:PreviousPage与Content页面有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将变量值从一个页面传递到另一个页面。在所有可用的方法中,我喜欢PreviousPage.FindControl(),因为它允许我访问上一页控件并获得值,而不用担心安全等问题。但我发现,一旦页面被发布,我在PreviousPage中获得的唯一控件是母版页,并且PreviousPage.Controls集合中没有内容页面的控件。我检查了Request.ServerVariables(HTTP_REFERER),发现页面被正确引用。有没有人知道这是否可行或是否有其他解决方法?

谢谢。

I''m trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.FindControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Controls collection. I checked through Request.ServerVariables("HTTP_REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
Thanks.

推荐答案


我正在尝试将变量值从一个页面传递到另一个页面。在所有可用的方法中,我喜欢PreviousPage.FindControl(),因为它允许我访问上一页控件并获得值,而不用担心安全等问题。但我发现,一旦页面被发布,我在PreviousPage中获得的唯一控件是母版页,并且PreviousPage.Controls集合中没有内容页面的控件。我检查了Request.ServerVariables(HTTP_REFERER),发现页面被正确引用。有没有人知道这是否可行或是否有其他解决方法?

谢谢。
I''m trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.FindControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Controls collection. I checked through Request.ServerVariables("HTTP_REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
Thanks.



你好,


为什么不试试Session对象。这是一种在会话中维护对象的简单方法,因此您可以轻松地在网页之间共享对象。



- Balaji U

Hello there,

Why don''t you try Session objects. It is an easy way to maintain objects within a session so you can easily share the objects between web pages.



- Balaji U



你好,

为什么不试试Session对象。这是一种在会话中维护对象的简单方法,因此您可以轻松地在网页之间共享对象。

- Balaji U
Hello there,
Why don''t you try Session objects. It is an easy way to maintain objects within a session so you can easily share the objects between web pages.
- Balaji U



I认为会话变量不应该用于将变量从一种形式传递到另一种形式(显然我们有多种其他方式传递变量)。我的立场是在多个页面上使用特定值时使用Session变量。无论如何,谢谢你的建议和时间。


有人遇到过我手边的情况吗?

I think Session variables should not be used for passing variables from one form to another (as evidently we''ve multiple other ways of passing variables). My standpoint is to use Session variable when a particular value will be utilized across many pages. Thanks anyways for your suggestion & time.

Anybody has faced the situation that I''ve at hand?



我正在尝试将变量值从一个页面传递到另一个页面。在所有可用的方法中,我喜欢PreviousPage.FindControl(),因为它允许我访问上一页控件并获得值,而不用担心安全等问题。但我发现,一旦页面被发布,我在PreviousPage中获得的唯一控件是母版页,并且PreviousPage.Controls集合中没有内容页面的控件。我检查了Request.ServerVariables(HTTP_REFERER),发现页面被正确引用。有没有人知道这是否可行或是否有其他解决方法?

谢谢。
I''m trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.FindControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Controls collection. I checked through Request.ServerVariables("HTTP_REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
Thanks.



您应该查看ASP页面生命周期。

浏览器向服务器发出请求,服务器编译所有代码并处理请求,数据被发送回浏览器,请求中使用的所有对象都被销毁。


因此,您无法访问上一页请求的信息。


为了使用每个页面上持久的数据,您必须在每次请求时(通过cookie,通过URL等)将此数据发送到服务器,或者将该信息保存在服务器上在会话中。


在网页之间传递信息的另一种有趣方式是使用Server.Transfer而不是Request.Redirect ....例如,假设您在页面上加载了LinkBut​​ton在LinkBut​​ton的OnClick事件(服务器端)中,您将使用Server.Transfer将用户定向到新页面...当使用Server.Transfer时,上一页请求中的所有变量将变为新页面可用于转移到用户的页面。使用Server.Transfer有一些特殊之处(浏览器中的URL确实发生了变化,因此用户无法预订标记等),所以在决定采用这种想法之前,你应该对此进行研究。


我自己更喜欢使用Session来为用户存储持久数据。


-Frinny

You should review the ASP Page Life Cycle.
A request is made by the browser to the server, the server compiles all the code and handles the request, the data is sent back to the browser and all objects used in the request are destroyed.

Therefore, you cannot access information on a previous page request.

In order to use data that is persistent on every page you have to either send this data to the server upon every request (via cookies, through the URL etc) or you save that information on the server in Session.

Another interesting way of passing information between web pages is through using Server.Transfer instead of Request.Redirect....eg say you have a LinkButton on the page that loads a new page, in the LinkButton''s OnClick event (server side) youwould use Server.Transfer to direct the user to the new page...when using Server.Transfer all variables on the previous page request become available to the page that the user is is transfered to. There are some peculiarities to using Server.Transfer (the URL in the browser does change so the user can''t book mark etc etc) so you should do research into this before deciding to go with this idea.

I myself prefer using Session to store my persistent data for the user.

-Frinny


这篇关于ASP.Net:PreviousPage与Content页面有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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