Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 I can't retrieve my dataset after a postback

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-03-19 : 00:06:19
I have two panels in my .aspx web page. I show the first panel pn1 that includes a datagrid dg and its datasource : ds.
First I do :

dg.datasource=ds
gd.datamembetr=....
dg.databind

When the user hits a push button I hide that panel pn1 and I show the panel pn2 that doesn t include the datagrid dg.

My problem is : when I push the button, I can t get access to the dataset ds anymore anymore after the postback.

When I do for example:

i=ds.tables(0).rows.count

I get the error:

System.NullReferenceException: Object reference not set to an instance of an object.

Thanks a lot for coaching



SamC
White Water Yakist

3467 Posts

Posted - 2006-03-19 : 12:37:51
You'll need to open the DB and retrieve the recordset again after a postback.

If it isn't "too" much data, you could store the recordset in a hidden field in the form...

<input type="hidden" name="MyPostData" Value="Data goes here">
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-03-19 : 16:57:26
thanks a lot
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-16 : 11:28:19
can we put any type of data in hidden fields: datasets, datarows,.....datagrid)

thanks
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-16 : 11:40:42
Ummm, theoretically, yes, you could put a string representation of a dataset or datatable into a hidden field, but, it will fill your page with a lot extraneous data and make it render very slowly. It also exposes your naked data to the world. Finally, it makes it easy for someone to hack your site by altering the values in the hidden field.

I can't think of any cases were storing anything but trivial values in a hidden field is a good idea. And even placing trivial data in hidden fields needs to be verified on postback.

The datagrid's state value is by default saved in encrypted format in the page's viewstate.

For large complex objects such datasets and tables you are best off to:
a) save it in a session variable
b) cache it, using web-caching
c) simply refetch the data

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-16 : 18:04:36
1/ i thgought we either use session or caching but not both since they serve the same perpous
2/ what s fetch mean?

Thabnks.
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-16 : 20:21:47
1) They serve similar purposes. Session is better for user-specific data. Caching is better for data shared by a number of users. There are times to use them both
2) Retrieve the data from the data source again -- not always the best option speed-wise, but it is the simplest. For infrequently used data it a good choice. It is also good for frequently updated data it often beats trying to keep the data store and memory versions of the data in synch.

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-17 : 00:52:55
2 more questions if u don t mind:
1/ how about cached data. are they always related to an application or can they be associated to only one user, or one session or only to one page.
2/re session variables the same in the different browser instances (if it s the same user using same computer) or if he opens a new browser, then those session vars ll not be available.
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-17 : 06:48:39
1) yes you can cache for a one user, by keeping using the session ID or other unique identifier in the cache key, but there is no real advantage to do this. Using a session variable does the same thing with less work
2) the browser instances will share the session info, but only for the same application. In other words, all the IE windows will share the same session info, but if if you open up Firefox or Netscape, etc. it will create a new session

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-17 : 11:23:54
thnkx
Go to Top of Page
   

- Advertisement -