views:

134

answers:

6

I've done my homework, I've read a lot of articles, I searched and searched but still couldn't find my answer and it's kind of getting on my nerves because there's a very popular question all over the blogs and websites and it's just the same as mine, the difference is the answer is not what I want!

To be clear, the two pages are only logically related in other words the values in my FirstPage.Aspx pass values to my SecondPage.Aspx so it control components and certain attributes of the controls in my SecondPage.Aspx, the SecondPage.Aspx is not a redirect or transfer from FirstPage.Asp. sorry am so sick of reading about all the answers but the one I actually need!

Consider the firstPage contains a textBox which get a value from the user or the web admin to set his preferences about the gridView page size on the SecondPage or a Text property of a label on the SecondPage

I want to explore my options to do so

PS: I was told to use a database to store values from the first page then on the page with my Label for example I connect to the database and retrieve the value and set it to the label...is this a best practice to let the page connect every time it loads to set some values somtimes it's just an int like 5, and most of the time I'd be connecting already to the database to display some table's data in a gridView or any databound control!

Thanks for your time =)

EDIT:

Sorry guys if I was a bit rude, It just hit me that I'm mainly getting the same answer that I read which is totally not my case!..and of course thanks to some of you mentioned the database solution, I hoped I could get an example or an article for my particular case since I think even it's simple but yet it's essential..I appreciate the help THANK YOU! and sorry I reacted a bit in my comments

+3  A: 

You can use:

  • Session variable
  • Cookie
  • Database value

each one of them have their own pros and cons

If you want the value to be stored the next time they come to page 2, use a database value. if not, use a session variable.

The database value will give you a persistent value, and you can then store other such user variables there.

the session will give persistent data, but only for the browsers current session. The data will be lost if their session times out.

From all you've stated, i would assume a database value.

ttomsen
I'm not sure but if those are my only options, i think the database solution makes sense but how come there's no examples, articles, or any reference about such a thing, I mean almost every dynamic website needs a page (admin page) to have control over the website resources and update the data on the other pages!
lKashef
@IKashef. Pretty much every dynamic website does use a database to do that. And there are **TONS** of example of how to connect to a database from ASP.NET!
tster
Yes am finally down with that, and I already use one to store data, articles, users. but i didn't know that it could be the right way to store also my controls settings to change them dynamically, AM NOT THAT NOOB! am past connecting to a database :S am just after the best practice to do so....please could you read the PS in my question again maybe it could help you understand my case more!
lKashef
+1  A: 

I'd suggest you start here: Get Started with ASP.NET

If I understand your question, you are looking to do Cross Page Posting. If one page isn't posting to a 2nd, you'll need to persist the data somehow (database, session, xml file, etc). But, from reading your question, you sound like you just want to cross page post...

Bryce Fischer
Actually it's not what it sounds like, the first page doesn't directly post to the other pagefor example you have an admin panel with a text box and you want to control another page's label control..it doesn't make since that after the web admin change the value, it redirects to the second page to make this change, instead it should take the value and pass it to the other page which is my problem here, without redirecting to it or anythingi think i might need to use a DB to store the admin preferences permanently until he decides to change them again, but i need example on how to do that
lKashef
then you'll need the persistence part. DB, XML, Flat File, etc.
Bryce Fischer
Check that link above on how to get started. It gets into depth on persisting to a DB
Bryce Fischer
"and most of the time I'd be connecting already to the database to display some table's data in a gridView or any databound control!" does that sound like I need to read that!....am okay with database and connection and commands and all stuff!...I just want a good example to be precise Admin Page and A Default.aspx...the admin takes a value from a textbox in the page and sets the label on the Default.aspx to it!
lKashef
Don't sound so defensive. Trying to help. All an admin page is is a form that saves data to the database. The text box writes it, the label reads it.
Bryce Fischer
Am just tired trying getting people to understand me!..and I failed this time!...anyway my bad Bryce, THANKS for your effort
lKashef
Its all good. was in a bad mood yesterday. sorry...
Bryce Fischer
We're in risky business lol, It's all good ;)
lKashef
+3  A: 

ASP.NET framework provides several mechanisms to maintain context that lasts across several HTTP requests. The data you want accessible across calls, can be stored in this context. All you have to do is decide how long do you want this context to be maintained (because it consumes resources), and if you want this context to be available across more than one server.

  1. Application State : Which is maintained for the lifetime of the application i.e. from when the application is first loaded by ASP.NET, till it is unloaded for whatever reason.
  2. Session State : ASP.NET is able to identify a series of HTTP requests emanating from a specific client (IP address), close to each other in time, as a session. It can create a session context that persists across such a session, in which you can store data that is accessible to the calls in the session. The session state can be made available across server boundaries by associating it with a DB or shared memory.
  3. Database
  4. Viewstate : You can use Viewstate to maintain context, but keep in mind that Viewstate is transferred over the wire for every request / response. It has been known to get quite large, specially if you use controls.
  5. Cookies : Again, transferred on the wire for each request / response.
Ziffusion
IMO, This is not a valid use of application state or view state.
tster
Even though it's not what i'm exactly looking for but you explained all my options pretty much, my bad I was looking for the perfect answer for my case and didn't pay attention to your answer...maybe it's not the appropriate one to solve my problem but i think it's the best..as a reference to all who want to get started on this part and don't have a clue about the optionsThanks +1
lKashef
+2  A: 

U can use cookies, session etc but if you want to pass something that defines the whole content of the page, like an ID of some sort, you might just want to put it in the QueryString. (ex: default.aspx?id=4)

Cons: everyone can read (or change) the value, not usable for critical data

Pros: everyone can read the value, and the link can be sent to others

user468524
I prefer this so long as the data being sent is what is defining what the other page is showing (like the database ID of the entity) but not if it is defining something like "how wide is the grid" or "is the tree expanded". However you can use an anchor in the query string to do that (anchors are what come after the '#' in the URL)
tster
it's simple as that, and PLEASE KEEP IN MIND!..they are two different pages, no redirecting or anything..Ex: PageOne has a label and PageAdmin has a textbox and a button...i want when the admin clicks the button the event handler of the click event to set the value of the text box to the text property of the label on the other page...and i don't think QueryString is the answer here!..it's probably database, BUT STILL! How =) !? will i connect to the database everytime PageOne loads to check the latest value in the database and set it to the label or what! seems consuming, isn't it ?
lKashef
Ok, I think I may understand better now. Are you saying that it happens in "real time". i.e., admin is open, text box is changed. User also has Default.aspx open and the label changes immediately?
Bryce Fischer
I think you got it right, and if by real time you mean the run time then definitely!
lKashef
I just want to know, if you have a different answer for me after it got more clear to you or you don't have any updates!
lKashef