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