Click here to Skip to main content
Sign Up to vote bad
good
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
Edited 19-Jul-10 18:25pm
Abhinav S335K

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

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
Your Filters
Interested
Ignored
     
0 Prasad_Kulkarni 407
1 Sergey Alexandrovich Kryukov 340
2 _Amy 331
3 Christian Graus 268
4 OriginalGriff 235
0 Sergey Alexandrovich Kryukov 6,649
1 Prasad_Kulkarni 3,281
2 _Amy 3,065
3 OriginalGriff 2,989
4 CPallini 2,696


Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 23 Nov 2010
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid