Click here to Skip to main content
11,932,168 members (64,026 online)
Rate this:
Please Sign up or sign in to vote.
I am trying to get an asp:SessionParameter of a SelectParameters, to use a property of an object in session
instead of having a string in the session like Session["CustomerID"]

Something like Session["Customer"] where the property is ((Customer) Session["Customer"]).CustomerID)

I don’t know the syntax to do that, if you can help, I’d really appreciate it

Thank you

My code:

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:DBConnectionString %>" xmlns:asp="#unknown">
        SelectCommand="SELECT * FROM getStoreCustomers (@customerID,@week,@day)"
            <asp:sessionparameter name="customerID" sessionfield="Customer" /> ?????? (what is the syntax to pass the property here?)
            <asp:controlparameter controlid="ddWeek" defaultvalue="-1" name="week" propertyname="SelectedValue" />
            <asp:controlparameter controlid="ddDay" defaultvalue="-1" name="day" propertyname="SelectedValue" />
The class I use is like any other class (but serializable)

    public class Customer
        public int CustomerID
Posted 19-Jul-10 15:57pm
Edited 19-Jul-10 19:25pm
Abhinav S407.8K
ıʇoʞɐlɐʞ ɥsɐʞɐɹd 20-Jul-10 1:21am
I don't think that you can bind the property of a class stored in session, in sessionfield you can specify only a key stored in session.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I just did resolve this issue by deriving my own class from SessionParameterInfo.

See this example as a start:

namespace MyNameSpace
	using System.Reflection;
	using System.Web;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	public class LoggedInUserSessionParameter :
		protected override object Evaluate(
			HttpContext context,
			Control control)
			if ((context != null) && (context.Session != null))
				var fieldName = SessionField;
				var liui = context.Session[@"CurrentUserInfo"] as LoggedInUserInformation;
				if (liui == null)
					return null;
					return liui.GetType().InvokeMember(fieldName, BindingFlags.GetProperty, null, liui, null);
				return base.Evaluate(context, control);

You than can register the control on your page:

<%@ Register Namespace="MyNameSpace" TagPrefix="mns" %>

And then use it like this:

<mns:LoggedInUserSessionParameter Name="LegalEntityID" SessionField="LegalEntityID" Type="Int32" />

Dalek Dave 23-Nov-10 4:40am
Good answer, Uwe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 23 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100