473,808 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ 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.Fi ndControl() 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.Co ntrols collection. I checked through Request.ServerV ariables("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 2281
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.Fi ndControl() 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.Co ntrols collection. I checked through Request.ServerV ariables("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.Fi ndControl() 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.Co ntrols collection. I checked through Request.ServerV ariables("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.Redirec t....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

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

Similar topics

10
3099
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 config does specify a machinekey setting: <machineKey validationKey="447C05E8B3A71401CC4CAE5513A7F1A3494A3618EE819316AAD1D58433F236A759D66FB4154500E01EB4E1BC1DE42046E2D652D391CB8367A1649438867A02EB"...
4
3317
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 time. I can't seem to get at the Placeholder from the target page. The first page has an empty placeholder, and the code-behind loads a user control dynamically and adds it to the placeholder. The user control grabs an ID from the querystring...
1
2557
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 - Server.Transfer("/Site/Template.aspx", true) - to a template page which displays the database related content. The Template page knows it's content because the page does exist in the SQL sitemap provider. The problem comes in with a button on...
2
1737
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 intellisense. It acts like it is not a class but compiles fine. Thanks, protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
0
1093
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 an array MostHits = ArrMH; } public String MostHits {
1
1271
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: ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/fedf234e-b7c4-4644-a9e8-c1c0870b043b.htm I do not see any deviations from the paosted code, yet the application throws an : "Object reference not set to an instance of an object." error Any suggestions would be appreciated. My complete code for both pages...
4
8568
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 they log in, it goes to the search result screen. But when I do, the PreviousPage variable is null. Once logged in, when I go from the search to the search results screen, PreviousPage is fine. I'm using the authentication built into dot...
1
1340
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 (Page.PreviousPage Is Nothing) Then Label1.Text = "Form sent" If Not (Page.IsCrossPagePostBack) Then If IsNothing(PreviousPage.FindControl("txtVertrek"))
2
2672
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
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.