.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Business Object properties and Session Variable

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I'm having trouble getting the properties of a Business Object between pages.  Right now on the main page's button click event, I instantiate a Business Object, assign its properties with user inputs, store it in Session Variable and open a popup via window.open.  On the popup I retrieve the Session variable and cast it to the business object and try to access its properties.

However in the popup Page_Load event, all the properties of the business object is returned as null.  I have no problem using this method with simple strings/integers instead ot the business object.  I'm not sure how to go about this, any suggestions?

Here's my code example:

// Button click event in main page        
protected void btnViewReport_Click(object sender, EventArgs e)
            ReportObj auditReport = new ReportObj();
            auditReport.PropA = 1;
            auditReport.PropB = "hello";
            auditReport.PropC = DateTime.Now;
            auditReport.PropD = new int[] {1,3,10,87,23};

View Complete Post

More Related Resource Links

Access property of object as session variable as declarative datasource parameter value


I am storing a custom "Organisation" object as a session variable. One of the properties of  the Organisation object is "OrganisationID" (integer).

I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    SelectCommand="spGetUserJobList" SelectCommandType="StoredProcedure">
        <asp:SessionParameter Name="OrganisationID" SessionField="OrganisationID" Type="Int32" />

However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")?

 I have tried this, which does not seem to work:

<asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />


Can I Assign class object to session variable?


Hi all, i have a class Emp and whether it is possible to save the object of this class in a session?

And after creating the session with object how can i store it in state service and how can i use the object from session??

thanks in advance...

Business object design in master details.


Hello guys, I have the following scenario,

  1. There is a master business object containing 40 fields
  2. 2 separate child business objects
  3. If I update a child record, I have to update master's 'Last modify by' status along with 3 or more fields in master
  4. For this purpose, I don't want to initialize a separate Master class object (as most of the fields are unused/wasted)
  5. The 'last modify by' also gets updated if the records in master get updated themselves

Currently I have separate business objects for master table, Child 1, Child 2 etc.

How do I control this in my business object design ? Do I break up my master object ? Say I extract last 'modify by ' into a new class, through inheritance or some other way ?

Is there a way that whenever child gets updated I use a 'small' class to update Master status only and whenever the master itself gets updated I do the same.

Problem is that I am having redundancy in my small class (Master class also contains 'Last Modify By ',

What would you advice. Please have your say. Thank you.

Edit  I am using webforms guys.

Session Variable issues


Hello everyone,

I ran into an issud to day with the follwoing code.  The strPanelOrder session variable is false, however, once it goes into the next if statement and sets the strTrimOrder to True, it changes the strPanelOrder session varialbe to true as well.  Why is this and how to I stop that from happening?

If Session(strPanelOrder) Is "False" Then
                If (strItemNumber.Length() = 10) And (strItemNumber.Substring(0, 2) = "FS" Or strItemNumber.Substring(0, 2) = "FC" Or strItemNumber.Substring(0, 2) = "DS" Or strItemNumber.Substring(0, 2) = "DC") Then
                    Session(strPanelOrder) = "True"
                End If
End If
If Session(strTrimOrder) Is "False" Then
               If (strItemNumber.Substring(4, 1) = "T") And (strItemNumber.Substring(0, 2) <> "AC") And (strItemNumber <> "Length") Then
                    Session(strTrimOrder) = "True"
                End If
End If


Thanks in advance for taking a look at this.



send data in class object from one page to another using session


hello everybody

now i hav stored all data like user name, data fatched from database of that user

and i stored that data and user name such as:

string strUserName="user name"

dataset ds =new dataset();// data of that user

now i wan yo send d whole data from my login page to user profile page

can anybody help me for that...................

and plz tell me that how much is this way is benifitial to send data from one page to another page

plz........kindly waiting for positive rply

How to store and retrieve multiple values in a single session variable .


I want to store employee name,designation and department in session variable and
retrieve in another page how to do this.

Textbox text populated by Session Variable wont update into SQL with new text


Hi everyone, I have what I think is a weird issue. I send text from one page to another via Session Variable. When page 2 loads, the text box has the session text set, but if the user changes the text and clicks the button, the SQL database is update with the original session text. If I remove the redirect from the page 2 button_Click method, then, the page refreshes with the textbox reverting to the session text and thr SQLDataSource has the session text added to it.

Why would the button click cause the textbox refresh with the text from the pageLoad before updating the data source?


Partial Class _1
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Session("UpdateProd") = "Have some text here to send to a textbox on page 2"
    End Sub
End Class

Partial Class _2
    Inherits System.Web.UI.Page


Retaining Datagrid Results using Session Variable


I have a page with 2 dropdown menus and 2 datagrids.
The datagrids get populated by a database based on a dropdown menu slection.

This page links to another page which in turn links back to the original.
If the user leaves the first page and then returns back I want to keep the dropdown menus and datagrids populated.

I tried doing this with session variables but can't get the datagrids to stay populated ...

    protected void btnSubmit_Click(object sender, EventArgs e)
        if (this.ddlName.SelectedIndex > 0)
            GridView1.Visible = true;
            GridView2.Visible = false;

            Session.Add("name", this.ddlName.SelectedValue);
            Session.Add("gridview1", GridView1.SelectedValue);

    protected void btnSubmit_Click1(object sender, EventArgs e)
        if (this.ddlLocation.SelectedIndex > 0)
            GridView2.Visible = true;
            GridView1.Visible = false;

            Session.Add("location", this.ddlLocation.SelectedValue);
            Session.Add("gridview2", GridView2.SelectedValue);

    protected override void Page_Load(object sender, EventArgs e)


what is role of object properties when using client side validations ?


I have been using properties and have idea that using properties with private fields we can implement validations and buisness rules in them.

But I am just thinking asp.net client side validation controls provide good strength and they provide good user experience as well. They can be used for any type of validation (using regular expression) on client side and their re-use is possible on server side. When validation controls are a must and they are powerful; is making properties not just wastage of time ?

Is there still some use of properties ? Please guide me.


session object security in asp.net 4

hi,So I'm developing a complicated solution where users need to register, on the web application. I'm not going to use asp.net forms authentication because it would be too complicated to make it work in my app. We do not have SSL, it doesnt need to be super secure but the only thing I am worried about is:When the user logins, he is authenticated, then his username is stored in an asp.net session object. Every protected page then check if there is a username, is there isn't he is redirected. Is this secure?Is there a way an attacker can manipulate a session object to have it store a valid username, which will fool the pages to think that user has logged in. Is there any way to make it slightly more secure without hitting too much on performance?All the options I see are all about forms authentication.Thanks so much

Session variable in Javascript

Hi, I had tried to use a Session variable in Javascript which are placed in the Header html. but got no luck. In my Init function, I intended to read the username value from database and place it in the session variable["username"].Then the username can be utilized in the second line of code shown as below. <script type="text/javascript"> //load session variable into "username" here. Sys.Application.add_load(Init); </script> <script type="text/javascript" src="http://api.art.com/api?service=api&v=3.1.9&user=<%=(string)Session["username"]%>"></script>Here are the code inside the Init:function Init () { WebService.GetAuthentication(getAuthenticationOnSuccess, getAuthenticationOnFailed); } function getAuthentication() { WebService.GetAuthentication(getAuthenticationOnSuccess, getAuthenticationOnFailed); } function getAuthenticationOnSuccess(result, context) { if(result) { getQueryStringInfo(); } } function getAuthenticationOnFailed(error) { showError(error); } Please help.Cheers,  

Managing business object locks on application level

Today I worked out simple application side object locking solution for one server scenario. My motivation came from ASP.NET architecture forum thread How to solve concurrent site issue where one user asks for locking solution that works without changing database. Here is my simple and primitive solution that should help this guy out. I added also sample solution to this posting. My solution is simple: Create class for locked items. Create manager class that holds locks and manages them. Clear locks when session ends. Create page to release all locks. If you need something more serious then you should keep locks information in database or better than that - use some lock server. Also you may consider developing WCF service. LockItem class As a first thing let's create class that keeps lock information. I call this class as LockItem. This class doesn't hold references to locked objects - only type and ID as there are many business layers that doesn't use globally unique identifiers for objects. public class LockItem {     public Type ObjectType { get; set; }     public int ObjectId { get; set; }     public string SessionId { get; set; }     public DateTime LockedAt { get; set; } } LockItem class also contains property for session because otherwise it is not possible to kno

query string or session variable or neither for this scenario?

Hello,example scenario: user login has a list of associated 'accounts' it has access to... this list of accounts is stored in a database table, say tblAccountAccessControl, something like:login, accountID-----------------------userA, account123userA, account456userA, account798userB, accountABCuserB, accountDEFetc..this info is used throughout the web application and determines the 'domain' of information the particular login has access to. For example there are many other tables that have the 'accountID' field and whenever a page pulls data from the table it only pulls data that the currently logged in user should be allowed to see, based on that tblAccountAccessControl data.the security question:1) do I need to query the database every time I need to get this list of allowed accountID's? I was about to use a plain old query string to pass a particular accountID to another page but quickly caught myself as I realized that would be a major security flaw (the receiving page was going to use that accountID to grab info from the database, and there would be nothing preventing a user from simply typing in a url manually to get data from an accountID they are not supposed to be allowed to view). So I then thought I'll just store the list of accountID's in a session state variable so they will be carried with the user throughout the sessi

Session Variable use / IsolatedStorage

I am using ASP.NET 2.0I am little bit confuse about using of Session Variable. I have a three page web application. When a user login, after verification of user credentials I get user ID from DB and store this ID in a session variable.Session("USERID") = 56by using this ID I can get 20 different values from database as User Full name, user date of birth, user location, user date of joining, User Commission rate  etc. I need some of these values in Page 1, some in page 2 and some values needed in Page 3My question is that what is the best method !01. After successfully login and getting the User ID, I take all these 20 values from Data Base and store these values in an ArrayList and store this ArrayList in a seesion and whenever I need to use any value I take these values from ArrayList which is save in Session variable.02. I only save the user ID in session variable and whenever needed any user preference data, by using this ID I run the sql query and get the data and use this.03. Can I take some benefit by using the IsolatedStorage for this purpose.

HTTPContext.Current.Session losing the variable sporatically

I have noticed a strange behaviour in my ASP.net 2.0 application. I have some logic in my aspx page that accesses some Session variables fine, then accesses some app_code and most of the time the HTTPContext.Current.Session returns the variable back fine.  However, I have noticed that sometimes this Session returns null, like it has lost it's "pointer" to the current HTTPContext. Is this a known bug, has anyone seen something like this before?   Any help would be appreciated, thanks, Mark. 

How to control the text and other properties in ResourceDictionary object that i wrote ?

I wrote some ResourceDictionary. This ResourceDictionary is actuly a button that i use - I created this button by using Rectangle and TextBlock ==> that mean that the my xaml look like the code below. The problem is that i cant change the font size and the text of the TextBlock. I can change is just from the xaml of the template. And ... How can i define some variable that will control on the rectAngle redius in runtime ? Someone can help ?? ? Thanks. ...<ResourceDictionary> <Style x:Key="MyBtn" TargetType="{x:Type Button}"> <Rectangle ... <TextBlock.... </ResourceDictionary> ...

Using a Variable in SSIS - Error - "Command text was not set for the command object.".

Hi All, i am using a OLE DB Source in my dataflow component and want to select rows from the source based on the Name I enter during execution time. I have created two variables, enterName - String packageLevel (will store the name I enter) myVar - String packageLevel. (to store the query) I am assigning this query to the myVar variable, "Select * from db.Users where (UsrName =  " + @[User::enterName] + " )" Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, enterName,. I select that and when I click on OK am getting this error.   Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C.An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E0C  Description: "Command text was not set for the command object.". Can Someone guide me whr am going wrong? myVar variable, i have set the ExecuteAsExpression  Property to true too. Please let me know where am going wrong? Thanks in advance.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend