473,466 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.Net : PreviousPage issues with Content page

26 New Member
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.
Apr 29 '08 #1
10 2246
balame2004
142 New Member
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.
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
Apr 29 '08 #2
rjvrnjn
26 New Member
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 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?
Apr 29 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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.
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
Apr 29 '08 #4
Frinavale
9,735 Recognized Expert Moderator Expert
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?
Wait a sec, you're just passing between Froms?
Why not using a hidden field?

I'm not sure but even ViewState might be possible....

-Frinny
Apr 29 '08 #5
Frinavale
9,735 Recognized Expert Moderator Expert
I'm trying to pass a variable value from one page to another...
Oh no, you said One page to Another Page.

In this case hidden fields and ViewState wont help you.
I still think that Session will be easier for you.

-Frinny
Apr 29 '08 #6
rjvrnjn
26 New Member
Thanks guys for the replies. I think I'll go with Session variable.
@Frinny, thanks for the detailed explanation but you said:
...Therefore, you cannot access information on a previous page request....
But MSDN says :
If the source and target pages are both ASP.NET Web pages and in the same Web application, you can read the values of controls on the source page while in the target page. You might use this strategy if the source page does not expose public properties containing the information you need.
This leads me to think that this is possible. Is there something else implied and I am missing it?

Server.Transfer indeed looked great initially, but found that it doesn't give the correct URL and hence is not useful to me.
Apr 29 '08 #7
rjvrnjn
26 New Member
Oh no, you said One page to Another Page.
In this case hidden fields and ViewState wont help you.
I still think that Session will be easier for you.
-Frinny
On the risk of sounding very naive, what is this different between Form & Page?
Apr 29 '08 #8
Frinavale
9,735 Recognized Expert Moderator Expert
On the risk of sounding very naive, what is this different between Form & Page?
Most of the time when you're making ASP.NET applications you just use the the ASPX pages as is. They are automatically generated for you and include one <form> tag. You can have more than one form tag on an ASPX page.


MSDN says :
If the source and target pages are both ASP.NET Web pages and in the same Web application, you can read the values of controls on the source page while in the target page. You might use this strategy if the source page does not expose public properties containing the information you need.
This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....


-Frinny
Apr 30 '08 #9
rjvrnjn
26 New Member
Most of the time when you're making ASP.NET applications you just use the the ASPX pages as is. They are automatically generated for you and include one <form> tag. You can have more than one form tag on an ASPX page.
I understand it better now. :)
MSDN says :
This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....
Hmm... they didn't mention that explicitly and hence had me wondering if it applies to any kind of redirection.
Thanks for the effort you took to explain. Thanks very much.
Apr 30 '08 #10
Frinavale
9,735 Recognized Expert Moderator Expert
This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....
Actually it appears that there are 2 ways to pass all the variables....but you have to use Cross-Page Posting. I've never done this myself and so I didn't even think about it until I continued reading that article you posted.

The interesting thing is that the Cross-Page Posting is only set up for specific controls (those that implement the IButtonControl interface)....so basically you can have a button that calls another ASPX page to do processing. In this case, in the ASPX page that the button calls to do this processing the Page.PreviousPage property contains the information that you're looking for.

Were you trying to use Cross-Page Posting??


You learn something new every day :D
Thanks for this article.

-Frinny
Apr 30 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
4
by: Alan Silver | last post by:
Hello, I'm doing a cross page post, and want to pick up information from the previous page. The problem is that the previous page contains a user control that is loaded into a Placeholder at run...
1
by: michael.neel | last post by:
Here is the setup: I have an SQL driven sitemap provider - when the user clicks on a database generated link - /Site/DBPages/Article1.aspx - a handler does a Server.Transfer -...
2
by: PeterKellner | last post by:
Is there something extra I need to do to make intellisense work when referencing a page class? Here is my working Page_Load from a aspx page. sourcePage does not get it's members listed with...
0
by: Jim McGivney | last post by:
I am trying to use the PreviousPage feature in asp.net 2.0 On the source (previous page) I have: protected void Page_Load(object sender, EventArgs e) { ..... Code to populate ArrMH //ArrMH is...
1
by: Jim McGivney | last post by:
I have been trying to get the values from a previous page on my target page. I have followed the help article:...
4
by: Bryce | last post by:
I have a search page that submits to a search results page. I have set the search results page to be authenticated, so when the user first tries to search, it redirects them to a login screen. When...
1
by: jeroen.bolle | last post by:
I'm trying to pass variables between pages using the post method. I have access to the the page where I've posted my form, but all the objects are empty... An extract of the code: If Not...
2
by: David C | last post by:
Will the Page.PreviousPage be able to read controls from a non-aspx page, e.g. an html page? Is there a better way to get info. from textboxes/controls? Thanks. David
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.