Click here to Skip to main content
12,953,541 members (51,809 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)"
        ProviderName="System.Data.SqlClient">
        <selectparameters>
            <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" />
        </selectparameters>
    </asp:sqldatasource>

The class I use is like any other class (but serializable)

[Serializable]
    public class Customer
    {
        public int CustomerID
        {
            get;
            set;
        }
    }
Posted 19-Jul-10 14:57pm
tucho143
Updated 19-Jul-10 18:25pm
Abhinav S415.2K
v2
Comments
ıʇ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
 
good
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 :
		SessionParameter
	{
		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;
				}
				else
				{
					return liui.GetType().InvokeMember(fieldName, BindingFlags.GetProperty, null, liui, null);
				}
			}
			else
			{
				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" />


Regards
Uwe
  Permalink  
Comments
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
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 23 Nov 2010
Copyright © CodeProject, 1999-2017
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