Link to home
Start Free TrialLog in
Avatar of kateL
kateL

asked on

ASP.NET Postback advice?

Hi Experts,

I am relatively new to ASP.NET although I've worked with win forms a lot.

In ASP.NET let's say you have a couple of private member variables and in the button click even you need to use these variables.

The postback is done before the handler gets called i.e. the variables are empty at the time you need them in the click event!!!

How can I manage this if the variables ARE NOT simple types like numbers and ints i.e. what if they are datatables, datasets, IList<> etc ...

For example I had the case where i had a datatable (and an IList<T> in another case) that I used as a datasource to a GridView. When the user clicked a row on the GridView I grabed the ID of that row and used it to find the correct row in the dataTable and do some processing ... but the datatable was NULL by the time I got to it!

So what's your adivce/best practises/url's on managing this?

Thanks a million
Avatar of sabeesh
sabeesh
Flag of United States of America image

Avatar of _TAD_
_TAD_

you need to store that information as cahce and then load the cahce back into the class variables during the ON_LOAD event.

ASKER CERTIFIED SOLUTION
Avatar of SystemExpert
SystemExpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kateL

ASKER

Hi sabeesh, that article is just about simple datatypes. I am asking about object like datatables and datasets etc..

Hi TAD, do you mean use Page.Cache? That's an application wide variable, right? I actually would need it on a per user basis ... so those that mean I would need to use the session variable or get it fresh from the database each time?

Hi SystemExpert, so what if I have 3 dataTables and I need to dynamically create and populate an ASP Table with the data from these tables depening on user input. Then during various events onthe page I need some or all of these 3 datatables for processing. How should I keep these tables in memory or should I retrieve them from the database each time?

Thanks a million for the help everyone, I'm learning loads even thinking about my q's.
I think you can bind only one datasource to a grid
Thanks
Avatar of kateL

ASKER

hi SystemExpert, yea that's true. I'm not using them 3 table as a data source. They are not bound to anything on the page

So what if during various events of my page I needed data from these 3 non-databound datatables?
If they required refresh during this events than
put those binding code outside the IsPostBack block else don't hit DB every round trip to server

Thanks & Regards
you can store your datavalues in session objects

Session["name"] = datatable;