Session variable with Class

I am changing an application that includes a public class.

I am adding a session variable that will pass between forms and hold any error messages encountered. This works fine except when it accesses the class. Then the session contents are lost.

I added a watch and when it enters the class I get the message 'Name session is not decared'.

I tried adding 'Inherits System.Web.UI.Page' but I get the error 'Cannot refer to an instance member of a class from within a shared method......'.

Any suggestions would be appreciated.

Posted On: Tuesday 27th of November 2012 10:26:39 PM Total Views:  700
View Complete with Replies

Related Messages:

can we session variable without working in classes?   (376 Views)
hi i want to ask can we use the session variable if we are not working in classes.... i mean when we create an application we define our own classes then we use session variable throughout application. but what if we are not working in classes cant we use it to save user name and then for further use in application em hell tensed:(
using HiddenField with session   (378 Views)
everybody... i need help with this code here Comments: these data will be inserted to a table in a database, in the code above , i get the name and comment from the user(textbox).But the date i get it from the following behind code ... HiddenField hidDate = (HiddenField)FormView1.FindControl("hidTimeDate"); hidDate.Value = DateTime.Now.ToString(); What i want is to get the name from an existing session.Can any one help please i don't know how can i do the that.... i tired doing this string username = Session["username"].ToString(); HiddenField uname = (HiddenField)FormView1.FindControl("name"); uname.Value = username; it's not working , it gives me the following error Quote{"Object reference not set to an instance of an object."}
How to use session arraylist to store multiple items from any from   (339 Views)
hi,friends please tell me how to store multiple values from multipal pages in session arraylist. I am trying like this ..after every button click event i will take new values. But the previous value get vanish and new value inserted session. So I gort only one value.So what is the solution. protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { string value= "value";//everytime i take different vales ArrayList cartList = (ArrayList)Session["ShoppingCart"]; ArrayList shoppingCartList = new ArrayList(); if (cartList != null) { shoppingCartList.Add(shoppingObj); } else { shoppingCartList.Add(cart); } } } Session["ShoppingCart"] = shoppingCartList; } This post has been edited by sumit jadhav: 05 July 2010 - 05:56 AM
session lost in IE   (305 Views)
I'm using session variables to keep a file name. The file name did not have any symbols or underscore.When I clicked a button to update the file, the session variable is lost.However, it happens on in IE. I've changed the configuration settings as the following: 1)Use cookies changed to auto detect. 2)InProc changed to State Server. In IE internet options, I've changed to allow session cookies and check override the cookies. After changing these settings,the session variable can be passed to Export button function but not Update button function.Anyone had idea how to solve this
session   (332 Views)
How to create a dynamic session in ASP.NET I have created dynamically textboxes(duing runtime only the number of boxes are known) in a form and i want to send the values to the next page how to do that[size=5]
Retrieving multiple data from session variable   (450 Views)
Currently, I'm storing multiple values into a session. (using listbox) I'm using those data to pull data from database (values in session is used in WHERE statement) I'm not quite sure how to retrieve data from session value so that I can use it in sql statement. Can you help me I'm posting code and display page code Session["genderList"] = genderList.Text; Session["hairList"] = hairList.Text; Session["eyeList"] = eyeList.Text; List selectedItems = new List(); foreach (ListItem item in this.state.Items) { if (item.Selected) selectedItems.Add(item); } Session.Add("state", selectedItems); Response.Redirect("search_result.aspx"); Below code is for display page (Just the sql code) This post has been edited by kmc10314: 21 September 2010 - 11:07 AM Datagrid value to array to a session   (298 Views)
, I am making a shopping cart site and on my browse products section i have a datagrid with a select button feature and when the select button is clicked it calls a method. Now my problem is that i need to store the item selected in a array so that they can add more items. That array has to be put into a session that will be used on another page. Now to get the specific value i need to store in the array i use MyDataGrid.DataKeys(CInt(E.Item.ItemIndex)) but i cant get the array to work or even a hashmap. I get a object reference null exception or not refering to an object reference. I was wondering if anyone has any clue what could would work.
How to get table values in aspx.vb coding session   (340 Views)
I have web page, In that I created table and loaded row values at run_time using javascript. Now I want to take a those table values in aspx.vb coding area, I tried it does not pull up my values even my table has 3 rows, but in aspx.vb area it shows row count as 0. How can I achieve this. I tried as mentioning runat="server". But It shows only that initial no. of row count only even I added new rows at run_time...
session id hijack   (249 Views)
i'm developing a site which involved the insurance informatin .. and it has flow structure like agent , broker and underwriter ... actually al tis information wil be generated and showed the output in pdf ... actually tid pdf document has to be opened only to the particular user .. eg- if agent can only sees that pdf file , in that link ter wil url embedded with session id ... actually from cookies can get session id and edit that session id and enter mean even for broker user can see the pdf file ... actually session id is hacked from tamper ip tool . please help me to solve tis solution ...
How to manage the session state outside the application   (262 Views)
Dear,i m facing some problem with my web application (developing in ASP.Net). i want to manage the session even after i closed the application on client if any client 'ABC' open my web application 'XYZ' then after some time when clent 'ABC' close the browser ie Application 'XYZ'. then after some time again open the application on same client 'ABC'. Plz tell me how i can maintain the same session on that client without assign new session to that client 'ABC'.can i solve this problem by storing the session in SQL Server.i don't want to create any cookie.plz give reply ...... tell me how i can solve this problem.with regards,Ankush
Login Status not clearing session when click logout   (290 Views)
Hi. I'm developing a web application, where one of the requirement is to automaticly logout user after 15 mins interval. I set this in my web.config where user will be automatically logout (to login page) after 15 minutes. I have a listing to show which users is online.But this users will be shown when user is logged in and will remain as online for 15 minutes eventhough user click logout button (using login status).It seems like the when i click logout, the seesion time is still ongoing. I want to clear the session time when i click the logout button. Means now session will timeout after 15 minutes,but when i click the logout button,i want the session to be ended before that 15 minutes. I tried using these codes to end the timeout ; Session.Clear(); Session.Abandon(); Session.Remove(); FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); Roles.DeleteCookie(); but nothing is seems to be working.The timeout will only end after the 15 minutes. I used in the event of LoginStatus1_LoggedOut and/or LoginStatus1_LoggingOut, but i cant figure out why its not working. Can anyone help me on thisAny ideas/suggestion
using session code behind   (247 Views)
i wonder if anyone can help me, im really stuck,i have produced a vb code behind file where i have a sub in a class which creates a session to locate a clientname in the querystring, my problem is that the vb file compiles but when i try to call this vb file from an aspx page it doesnt work.The vb code looks like:Imports SystemImports System.WebImports Microsoft.VisualBasicnamespace IIRFHeaderTestpublic class HeaderClass1 public function GetClientName() As string dim MyClientName, MyQueryString as String 'var for the whole string in the url Dim ObjectHttpRequest,SecondOjectHttpRequest As HttpRequest if HttpContext.Current.Session("SessionMyClientName") = "" then MyQueryString = ObjectHttpRequest.ServerVariables("QUERY_STRING") if Strings.InStr(MyQueryString, "ClientName") = False Then MyClientName = "IIRF" else MyClientName = SecondOjectHttpRequest.QueryString ("ClientName") end if HttpContext.Current.Session ("SessionMyClientName") = MyClientName Dim valuetype As String valuetype = HttpContext.Current.Session ("SessionMyClientName") end if end functionend ClassEnd namespaceand the aspx file looks like ' stupid line doesnt worksub Page_Load 'dim clientname as new HeaderClass 'notelabel.Text = clientname.GetClientName() dim objASPNetLibrary as HeaderClass1 objASPNetLibrary = new HeaderClass1() objASPNetLibrary.GetClientName() 'objASPNetLibrary = null 'says use system.dbnull 'objASPNetLibrary = Is null 'says experssion is required 'objASPNetLibrary Is null 'experssion is not method objASPNetLibrary = null end subi do not require any soultions with visual studio coz im not using that, this is all built in another software package.I know the subroutine is working correctly because i have put it into a simple aspx file and the code is correct, but i have been unable to get the my namespace to work.PLEASE HELP ME BEFORE I GO INSANE
Loosing session in new window   (319 Views)
When I open a new window from my ASP.NET form using JavaScript's"", session variables seem not to be available to that newform.Is there a way I can make sure that I can still access the dataThe data in question is too big to be sent in the Request.QueryString,so I really wouldn't know what else to do...
How to retrive value of javascript control into session in   (268 Views)
i want to retrive value of textbox into session in using C# language.
Redirecting to login page even session havent time out   (333 Views)
I'm having a problem here with my web application. I set the sessionstate timeout to 15 minutes and form timeout for 15 minutes as well where in form timeout,it will redirect the page to login page ; By right,it should only redirect the page to login page only after the session ends (timeout).But i dont understand why the page is redirected to login page even before the session timeout ends.This makes user unable to login again because the user is already logged in (session havent end). I m using iis 7.5 Do i missed something hereAny ideas This post has been edited by pwtc222: 05 December 2011 - 02:00 AM
using sessions in databases   (331 Views)
I have a problem with using sessions in my project called Online library in school.I've created SQL Database and login on user(new or existing) and now i have difficulies with the part when a sectain,present user log on the system and he/she wants to see how many books he/she has reserved in the past period.I know that I must use sessions like in logging but i don't know how to do that,or how to implement them.I would like some exact answers form somebody of you.
How to avoid session hijacking   (511 Views)
How to avoid session hijacking
session variable losing values   (230 Views)
I have a click button in my page and when I click it more than one time the value for session variable losing the stored value. anybody has an idea why this is happening. I am getting the value for session varialbe form another page.thanksCODEProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim TmReview As String TmReview = Session("TmId") 'Response.Write("Here is the value" & TmReview) If Not IsPostBack Then Label1.Text = "Select Review Participants for TM " & TmReview MemoReviewers() CheckReviewers(TmReview) End If End SubSub CheckandUpdateDb() Dim strReviewrsId As String = "" For Each li As ListItem In cblReview.Items If li.Selected Then strReviewrsId = strReviewrsId & li.Value & "," End If Next strReviewrsId = Left(strReviewrsId, Len(strReviewrsId) - 1) Session("TmReviewrsId") = strReviewrsId Dim TmReview As String TmReview = Session("TmId") Dim strTechMemoConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\DataBase\techmemo.mdb") & ";" Dim MyTechMemoConn As New OleDbConnection(strTechMemoConn) Dim strStringBuilder As StringBuilder strStringBuilder = New StringBuilder With strStringBuilder .Append("SELECT * from tbTM WHERE TM =" & "'" & TmReview & "'") End With Dim cmdReview1 As OleDbCommand = New OleDbCommand cmdReview1.Connection = MyTechMemoConn cmdReview1.CommandType = CommandType.Text cmdReview1.CommandText = strStringBuilder.ToString Dim adReview1 As New OleDbDataAdapter(cmdReview1) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adReview1) Dim dsReview1 As New DataSet adReview1.Fill(dsReview1, "ReviewList") Dim count As Integer = dsReview1.Tables("ReviewList").Rows.Count Response.Write(TmReview) Response.Write(count) End Sub
Moving from InProc sessions to (SQL Server) Out-of-Process sessions   (310 Views)
I am in the process of migrating my application from using InProc sessions to Out-of-Process sessions and I am concerned about the performance penalties. Here's my problem regarding storing of objects in the session:The object being stored consists mainly of data retrieved from a database, so I'd like to know which is more efficient and better in terms of performance:1. store the entire object in the session. The object contains data members of both "basic" and "non-basic" types.2. store the object in the session, serializing only data members of "basic" types, and reconstructing more complex data members in the IDeserializationCallback.OnDeserialization method. Reconstructing the complex data members would involve making database calls.3. store an identifier as a string or other "basic" type in the session, and use that identifier to reconstruct the object. Reconstructing the object would involve making database calls.4. store each of the data members of "basic" types from that object in the session directly as strings or other "basic" types, and construct the complex data members from the available information.*** 3 of the "non-basic" data members in the object are used on every page of the application. ***Question: How does serializing/deserializing compare to fetching information from the database each time a page is accessed (in terms of efficiency and performance)
Using session in back button what do you think?   (265 Views)
Hi all,I have to code a bit of a pain of a back button. Its not required on all pages but where it is required there are quite a few different factors that need to be address, like for instance i have a favourites folder page that links to products, once on products you can add the product to another favourites folder or send to a friend etc. Obviously, moving around in this manner changes the referrer of the page so its not that simple to do that. What i was think, that on certain pages where they link through to a page with a back button and can be navigated from that i would place the "referrer" in session, which gets updated when users move to specific pages.For instance it would set the session("referrer") = "folderlister.aspx" when comming from the folder lister page, but when the user comes from the productLister.aspx page the session will be updated to represent this.Does session sound like a good idea in this situation, i dont really use it that much and probably not as much as i should, and input would be great