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


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

static variables on asp.net pages

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net
 

Hello guys. Believe it or now, i have just found that that static objects in classes (pages) hold the same value for that same page even with two different users logged in.

I have a page where the user fills the name and id of a customer (page a) for example and then puts it inside the user session, redirects to page b and on that page writes a report based on that customer and saves it to the database.

We are getting reports that when the first user saves the report, the values of the second user gets saved.

My question is, how to handle the user's data without using static objects inside classes? The click method of button just passes the sender and event arguments, so i cannot pass for example a DataTable through it, and i only use session variables to store information that has already being validated just before sending the user to the next page.

That's why i used static objects, so methods like click inside of buttons could access the data.

Is the only way to do this is to store objects (like a DataTable in my example) in the user's session and then retrieve, update and put it back in the session each time i need to use it? I always though the user's session should be as small as possible.




View Complete Post


More Related Resource Links

Sharing of Non-Static member variables of a class using .NET Remoting

  
This kind of weird. I am trying to host an object of a class X (a class library class). This is a SAO and I have set the WellKnownMode as Singleton in the server configuration. <wellknown mode="Singleton" When multiple clients fetch the instance of the class X they can share the static member variables. Any changes made to the static variables are visible to each other. The problem is with the non-static member variables of the class. Each instance is having a local copy of the non-static variables. Why should that happen in case of a Singleton mode? Am I missing something for which this is happening? Any help will be appreciated.  A for apple, B for boy, C for c++

session variables and master pages

  
Hi all: I have a master page and 2 content pages. In the master page I use a session variable. As it, I suppose this session variable is read by the two content pages. But it isn't working. This session variable is read by the first content page and not the second. Why? Thanks in advance if you can help me      

Behavior of static classes/variables

  
Hi, I have a static class, that contains some static DataTable-variables.. In some of them I fill the tables from my database and one of them even does some file-checking..I'm concerned about performance in these variables.. How to they behave? Is it called once in the applications lifetime or everytime I call for the variable?What I mean is, if I have a loop with 500 runs and I use one of the static variables in the loop, is the code that fills the datatable executes 500 times or just once?

static variables throughout application

  

hello frnds

i am developing a website in asp.net

i have created a class "Utility" in App_Code Folder

this class contains a static object of another class(LoginInfo) as described below:

public class Utility
{
public static LoginInfo CurrentUser = new LoginInfo();

}


This LoginInfo Class is my business object which only contains 2 properties UserID and UserName

Now what i am doing on my login page, after user authentication i am setting these properties with current logged in UserId and UserName

protected void Login_Click(object sender, EventArgs e)
    {

        if (Authenticated User)
        {
         
        Utility.CurrentUser.UserID = "001"; //ID of current logged in user
        Utility.CurrentUser.UserName = "Admin" //Username of current logged in user;

        }
        
    }


I am using this CurrentUser object on my webpage to get userid and username.

It works fine, but after few minutes my CurrentUser.UserID and CurrentUser.UserName is set to blank string. 

I am not able to figure out what is the problem. may be due to asp.net recycles.

Please help me how should i solve this problem? Is there any other way?

Thanks



Pages showing different static content

  

I have two aspx pages that both use the same master page. Master page is more or less the default from VWD 2010 web application (Site.Master).

So both page A and B have the same:

<%@ Page Title="Sample web app" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="PageA/B.aspx.cs" Inherits="WebApp.PageA/B" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">,
    <link href="Styles/Table.css" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
.
.
.
</asp:Content>

The difference when shown in web browsers is (tested on Chrome and Firefox) that PageB looks like it has one more blank row/space on top of the page. How is this possible?

Thx,

M


Static Variables in session

  

I am creating a static variable and adding to session.This variable has value that is user specific. Now I am getting a problem with this users are complaining that they are getting values that should be another users. It's like a mix up with session. Could this be because of static variable declaration?



Session variables value lost between pages

  

Hello,

          I am using Session ID Manager in all the pages of the website, but I am losing session variables in between the pages. what should I do to save the values of session variables.


Thank you

Regards

Anoop


Static "forms" used as a background to the XPS fixed pages to cut down the time to create XPS file

  

Hi,

with Postscript I can define a resource (a static reusable form in this case) and reference that resource on any page I chose without having to recreate all the drawing instructions stored in that form resource.

How would I be able to do something similar with XPS?  Can I create a grouping of UIElements (drawing / text / image) as a resource stored at the FixedDocument level and then just include a reference to that resource on specific FixedPages?

Would seem illogical in the XPS file format to not be able to merge a single resource on the fixed pages which is a group of static UIElements which appear exactly the same on each of those pages.  Would cut down on repeat elements on every page and should end up with a smaller file size.

Thanks!

 


Why do session variables disappear on redirect between pages in IFrame?

  

I have a web site A with IFrame linked to web site B. A and B are located on different servers. B site has several pages (BHome, B1, B2).
When B site redirects from BHome page to Bx all session variables get cleared.

I can’t find why all session variables disappear.


Do you have any ideas?


High Performance ASP.NET - Speeding Up ASP.NET Pages

  
have been writing a series of blog posts, which I have named High Performance ASP.NET Websites Made Easy! There is no rhyme or reason to the order of these posts and certainly can be read in any order:

Developing High Performance and Scalable ASP.NET Websites
Avoid Chatty Interfaces Between the Tiers in Your ASP.NET Web Application
ASP.NET Page Profiling - Page Tracing - High Performance and Scalable ASP.NET Websites Made Easy
Web Applications: N-Tier vs. N-Layer - Benefits and Trade-Offs
Query Analyzer - Sql Server Database Indexes and Execution Plans

Static Class for Beginners

  
In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

SharePoint Application and Site Pages - Part 1 of 2

  
In this first part of the two part series, Steven covers the differences between Site and Application pages in SharePoint 2007, why each may be used in various circumstances, and prepares for the construction of a menu located application page. After a brief introduction he examines the concept of Site Pages and Application Pages separately in detail with supported screenshots.

SharePoint Application and Site Pages - Part 2 of 2

  
As the second article in a two part series, Steven examines the attributes and details of a SharePoint 2007 application page, including the construction and feature deployment of the same page based project. Since this is a WSS level objective, as opposed to MOSS, you will not need MOSS to work with the code included in this project. Windows Server 2003, WSS, and Visual Studio 2005 are all that is needed, with no additional add-ons. He provides a detailed analysis of each step involved in the creation and deployment of the project.

Application Vs. Content Pages in SharePoint

  
SharePoint has two types of ASPX pages. One type is the application page, also known as a _layout page. The other type of ASPX page is a content page, also known as a site page. Each of these page types is stored in a different location in SharePoint. When developers create custom ASPX pages, they must decide on the page type.

Master Pages in MOSS 2007

  
'MasterPages' feature in sharepoint 2007 makes the entire customization job easy.In 2003 we used to face lot of issues to get the same look and feel and the standard behaviour for overall site. In 2007, customizing the look and feel for the entire site can be done in a simple way by using 'MasterPage' feature.

How to Pass Values Between Web Pages ASP.NET

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

How to Pass Values Between ASP.NET Web Pages

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.
Categories: 
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