VB.Net: Postback woes

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
If I create a dataset within the PageLoad of a webform, AND, I create this only if the page is NOT a PostBack, then why can't I access my dataset later on if I attach code to another control?

Surely I don't have to attach each dataset to a viewstate do I?

Example.

If the page is loaded and it's NOT a postback then create a dataset with a table and response.write the table count of the dataset. Result = 1.

On a textbox control, when I press return (thus forcing a postback), Response.Write the table count of the dataset. Result = 0.

:confused:
 
U would need to create the dataset on every page request regardless of whether it's a postback or not.

You could store it in session if you didnt want to create it everytime. Look at

Application
Session
Context
and Cache.
 
Cheers mate.

Done something like this a while ago, it's all starting to come back now.

Can't use Session state as the session only lasts a set-period of time. I know I could increase the time on the server, but of course this is going to take up system hog.

Viewstate is an option, but it means the page been downloaded from the server is about 300k per postback. Not a great deal of data, but still a wee-bit too time consuming.

Cache is something I've not used before so will probably take a look at that.

Weird really 'cos if I bind the data to a datagrid it retains it without any problem, doing it behind the scenes in the page load I've got to store it somewhere.

Cheers anyway..
 
The reason the it holds when bound to a grid is because the grid has viewstate, where as the datasource doesnt.

U can serialise the datasouce and hold the information in XML on the disk, and then load it back in when required. Something that can work really well.
 
~J~ said:
Viewstate is an option, but it means the page been downloaded from the server is about 300k per postback. Not a great deal of data, but still a wee-bit too time consuming.

There's an article here which describes how to take viewstate out of the page.
 
Back
Top Bottom