If i use the SqlDataReader in my ASP Site...I assign a bunch of strings to items from the database...I want to maintain them from page to page....I want it to work like this
I have page one called "Fruit", when I click "Apple" on the fruit page, I want my "Apple" page to sort of keep the history of where i am clicking from page to page so i want to make label and have it like
Fruit - Apple
then when i click apple juice link for that page
the apple juice page will have...
Fruit - Apple - Apple Juice
Now will i have to maintain these varibles in Session Varibles?? How do i keep these varibles the same from page to page...Or once i assign them in the code behind will they stay the same from page to page and i just use them like regular varibles???
You could use Session, but in general it is better not to use server memory but to store the data in ViewState. The mechanisem is the same.
Session["MyVar"] = ..
or
ViewState["MyVar"] = ..
You can store the variables in the actual click callbacks and retrieve the in page_load event.
HTH's
So that mean if i have a value in a textbox like
Dim ad As String = "Hello"
TextBox1.Text = ad and I want my testbox to say hello no matter how many times i refesh my page i should do something like
ViewState("ad") = TextBox1.Text???
Is this how that should work?
actually, all the server control (textbox included of course) maintain their own viewstate so you don't have to worry about that. It would just be something like if you created your own variable (int i) for example that you have to worry about it.
Peter Sorry I jump in.
Just want to add that you can use Cache as well to store data that use more often, Cache can be used across Sessions and Pages, the best part about Cache is has an expiration time. Using Cache to store data will improve the performace of you website. Just my 5 cents, again nothing wrong in Peters answer, he is spot on!
Im sorry but i dont follow....I have a label that has a textvalue.....When i click label 2 the page refreshes and shows only label2.Text Value label1.Text value goes away but i did not tell it too....So how do i keep label1.Text there no matter if i reload the page or not?? do i code?
ViewState(label1.Text) to keep the value that i intially assigned it there?
0 comments:
Post a Comment