 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 5th, 2007, 04:58 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Session Parameter with Custom Object
Dear All,
I am using ObjectDataSource on a form. I want to use Session as its Parameter however within the session I have custom object stored rather than a string or int etc. How do I use this with ObjectDataSource?
Help will be much appreciated.
Thanks in anticipation.
Tahir
|
|

February 5th, 2007, 05:01 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In the Selecting event, you can retrieve the object from the session, cast it, do whatever you want with it, and then reassign it to the parameter collection.....
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

February 5th, 2007, 05:06 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Does that mean I dont have to define the parameter at design time i.e.
<SelectParameters>
<asp:SessionParameter Name="ABC" SessionField="XYZ /> </SelectParameters>
|
|

February 5th, 2007, 05:26 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Have you tried it?
If you use asp:SessionParameter, aren't things taken care of automatically?? (Haven't tried this yet)
Otherwise, you can define the parameter as a simple <asp:Parameter> and set it in code behind.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

February 5th, 2007, 05:37 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
While you are here, I read your article yesterday and have posted a query there. Will you be able to reply on that whenever your ready.
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416
|
|

February 5th, 2007, 05:38 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Oops you JUST posted it. Let me read it. Many thanks dear.
Tahir
|
|

February 5th, 2007, 08:05 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I have tested this and it works. Within the DAL the method should accept the object of type you have stored in Session. Then by using SessionParameter it passess the object. That object you are passing should also be marked Serializable.
In doing this I have encountered another issue. In a form when user clicks an item of a gridview, I want to store the DataItem (which in effect is an object of type I want to retrieve on next page) in a Session. It gets Nothing (null) when I try this behind SelectedIndexChange event!! I have template column (html checkbox) in first column of the grid, can that be the problem? The grid is binded to ObjectDataSource and I want to retrieve the Custom Object when user selects the grid. How can I accomplish this?
Many thanks
Tahir
|
|

February 6th, 2007, 05:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Take a look here
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.dataitem(d=i de).aspx
and here:
http://www.pluralsight.com/blogs/fri.../24/11975.aspx
The DataItem is only available during and after the RowDataBound event.
In your case, it's probably best to retrieve the DataKey and then fetch the single item from your DAL based on the unique key.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

February 6th, 2007, 09:57 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Many Thanks
Tahir
|
|
 |