Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
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
 
Old February 5th, 2007, 04:58 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old February 5th, 2007, 05:01 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 5th, 2007, 05:06 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Does that mean I dont have to define the parameter at design time i.e.

<SelectParameters>
<asp:SessionParameter Name="ABC" SessionField="XYZ /> </SelectParameters>

 
Old February 5th, 2007, 05:26 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 5th, 2007, 05:37 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


 
Old February 5th, 2007, 05:38 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Oops you JUST posted it. Let me read it. Many thanks dear.

Tahir

 
Old February 5th, 2007, 08:05 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 6th, 2007, 05:32 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 6th, 2007, 09:57 AM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Many Thanks

Tahir





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter object malfunction - out parameter dash dev C# 2005 6 December 4th, 2007 12:58 PM
Problem in Parameter Object Lalit Pradhan ADO.NET 3 July 9th, 2005 01:51 PM
Accessing Session variables from custom class mohyneenm ASP.NET 1.0 and 1.1 Professional 2 January 26th, 2005 07:25 PM
How to get request object parameter vikas verma Pro JSP 0 December 22nd, 2004 12:52 PM
Custom session handling dimitri p Pro PHP 2 July 31st, 2003 02:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.