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:  392
View Complete with Replies

RELATED TOPICS OF ASP.NET PROGRAMMING LANGUAGE




can we session variable without working in classes?

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\t cant we use it to save user name and then for further use in application\t em hell tensed:(
VIEWS ON THIS POST

149

Posted on:

Friday 23rd November 2012
View Replies!

using HiddenField with session

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."}
VIEWS ON THIS POST

196

Posted on:

Saturday 24th November 2012
View Replies!

How to use session arraylist to store multiple items from any from

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
VIEWS ON THIS POST

154

Posted on:

Saturday 24th November 2012
View Replies!

session lost in IE

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 ASP.net 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
VIEWS ON THIS POST

130

Posted on:

Saturday 24th November 2012
View Replies!

session

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]
VIEWS ON THIS POST

183

Posted on:

Saturday 24th November 2012
View Replies!

Retrieving multiple data from session variable

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
VIEWS ON THIS POST

227

Posted on:

Saturday 24th November 2012
View Replies!

ASP.net Datagrid value to array to a session

, 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.
VIEWS ON THIS POST

107

Posted on:

Saturday 24th November 2012
View Replies!

How to get table values in aspx.vb coding session

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...
VIEWS ON THIS POST

199

Posted on:

Saturday 24th November 2012
View Replies!

session id hijack

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 ...
VIEWS ON THIS POST

137

Posted on:

Saturday 24th November 2012
View Replies!

How to manage the session state outside the application

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 side.eg 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
VIEWS ON THIS POST

142

Posted on:

Sunday 25th November 2012
View Replies!

Login Status not clearing session when click logout

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
VIEWS ON THIS POST

173

Posted on:

Sunday 25th November 2012
View Replies!

using session code behind

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\t\tpublic function GetClientName() As string\t\t\t\tdim MyClientName, MyQueryString as String \t\t'var for the whole string in the url\t\t\t\tDim ObjectHttpRequest,SecondOjectHttpRequest As HttpRequest\t\t\t\tif HttpContext.Current.Session("SessionMyClientName") = "" then\t\t\t\t\t\tMyQueryString = ObjectHttpRequest.ServerVariables("QUERY_STRING") \t\t\t\t\t\tif Strings.InStr(MyQueryString, "ClientName") = False Then\t\t\t\t\t\t\t\tMyClientName = "IIRF"\t\t\t\t\t\telse\t\t\t\t\t\t\t\tMyClientName = SecondOjectHttpRequest.QueryString ("ClientName")\t\t\t\t\t\tend if\t\t\t\t\t\tHttpContext.Current.Session ("SessionMyClientName") = MyClientName \t\t\t\t\t\tDim valuetype As String\t\t\t\t\t\tvaluetype = HttpContext.Current.Session ("SessionMyClientName")\t\t\t\tend if\t\tend functionend ClassEnd namespaceand the aspx file looks like ' stupid line doesnt worksub Page_Load\t\t'dim clientname as new HeaderClass\t\t'notelabel.Text = clientname.GetClientName()\t\t\t\tdim objASPNetLibrary as HeaderClass1\t\t\t\tobjASPNetLibrary = new HeaderClass1()\t\t\t\tobjASPNetLibrary.GetClientName()\t\t'objASPNetLibrary = null \t\t'says use system.dbnull\t\t'objASPNetLibrary = Is null \t\t'says experssion is required\t\t'objASPNetLibrary Is null \t\t'experssion is not method\t\tobjASPNetLibrary = null\t\tend 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
VIEWS ON THIS POST

109

Posted on:

Sunday 25th November 2012
View Replies!

Loosing session in new window

When I open a new window from my ASP.NET form using JavaScript's"window.open", 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...
VIEWS ON THIS POST

152

Posted on:

Monday 26th November 2012
View Replies!

How to retrive value of javascript control into session in asp.net

i want to retrive value of textbox into session in asp.net using C# language.
VIEWS ON THIS POST

101

Posted on:

Monday 26th November 2012
View Replies!

Redirecting to login page even session havent time out

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
VIEWS ON THIS POST

127

Posted on:

Tuesday 27th November 2012
View Replies!

using sessions in databases

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.
VIEWS ON THIS POST

124

Posted on:

Tuesday 27th November 2012
View Replies!

How to avoid session hijacking

How to avoid session hijacking
VIEWS ON THIS POST

200

Posted on:

Tuesday 27th November 2012
View Replies!

session variable losing values

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\t\t\t\tDim TmReview As String\t\t\t\tTmReview = Session("TmId")\t\t\t\t'Response.Write("Here is the value" & TmReview)\t\t\t\tIf Not IsPostBack Then\t\t\t\t\t\tLabel1.Text = "Select Review Participants for TM " & TmReview\t\t\t\t\t\tMemoReviewers()\t\t\t\t\t\tCheckReviewers(TmReview)\t\t\t\tEnd If\t\tEnd SubSub CheckandUpdateDb()\t\t\t\tDim strReviewrsId As String = ""\t\t\t\tFor Each li As ListItem In cblReview.Items\t\t\t\t\t\tIf li.Selected Then\t\t\t\t\t\t\t\tstrReviewrsId = strReviewrsId & li.Value & ","\t\t\t\t\t\tEnd If\t\t\t\tNext\t\t\t\tstrReviewrsId = Left(strReviewrsId, Len(strReviewrsId) - 1)\t\t\t\tSession("TmReviewrsId") = strReviewrsId\t\t\t\tDim TmReview As String\t\t\t\tTmReview = Session("TmId")\t\t\t\tDim strTechMemoConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\DataBase\techmemo.mdb") & ";"\t\t\t\tDim MyTechMemoConn As New OleDbConnection(strTechMemoConn)\t\t\t\tDim strStringBuilder As StringBuilder\t\t\t\tstrStringBuilder = New StringBuilder\t\t\t\tWith strStringBuilder\t\t\t\t\t\t.Append("SELECT * from tbTM WHERE TM =" & "'" & TmReview & "'")\t\t\t\tEnd With\t\t\t\tDim cmdReview1 As OleDbCommand = New OleDbCommand\t\t\t\tcmdReview1.Connection = MyTechMemoConn\t\t\t\tcmdReview1.CommandType = CommandType.Text\t\t\t\tcmdReview1.CommandText = strStringBuilder.ToString\t\t\t\tDim adReview1 As New OleDbDataAdapter(cmdReview1)\t\t\t\tDim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adReview1)\t\t\t\tDim dsReview1 As New DataSet\t\t\t\tadReview1.Fill(dsReview1, "ReviewList")\t\t\t\tDim count As Integer = dsReview1.Tables("ReviewList").Rows.Count\t\t\t\tResponse.Write(TmReview)\t\t\t\tResponse.Write(count)\t\t\t\t\tEnd Sub
VIEWS ON THIS POST

117

Posted on:

Tuesday 27th November 2012
View Replies!

Moving from InProc sessions to (SQL Server) Out-of-Process sessions

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)
VIEWS ON THIS POST

154

Posted on:

Tuesday 27th November 2012
View Replies!

Using session in back button what do you think?

Hi all,I have to code a bit of a pain of a back button.\tIts 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.\tObviously, moving around in this manner changes the referrer of the page so its not that simple to do that.\tWhat 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
VIEWS ON THIS POST

103

Posted on:

Tuesday 27th November 2012
View Replies!