Click here to Skip to main content
Rate this: bad
good
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 15:57pm
tucho143
Edited 19-Jul-10 19:25pm
Abhinav S380.3K
v2
Comments
ıʇoʞɐlɐʞ ɥsɐʞɐɹd at 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 at 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
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 23 Nov 2010
Copyright © CodeProject, 1999-2014
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