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=dsgd.datamembetr=....dg.databindWhen 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.countI 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"> |
 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-03-19 : 16:57:26
|
thanks a lot |
 |
|
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 |
 |
|
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 variableb) cache it, using web-cachingc) simply refetch the dataDean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
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 perpous2/ what s fetch mean?Thabnks. |
 |
|
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 both2) 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 FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
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. |
 |
|
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 work2) 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 sessionDean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-05-17 : 11:23:54
|
thnkx |
 |
|
|