Asp.net Mvc - Session Variables Not Saving On Initial Page Load?
Mar 25, 2011
I have an MVC application which sets some session variables based on internal static IP addresses.I have built an ApplicationController to override the OnActionExecuted sub in MVC for data that I need to use throughout my application.However, the code below, which is just a snippet of my code but is edited for my post, only partially works. On initial page load, the session variables aren't saved, but after a page refresh they are. The issue I have is that these need to be saved on the initial page load.
If Session("Item1") = Nothing Then
If IpAddressShort <> "" Then
Dim locInfo = cmsRepository.GetInfoBasedOnLocation(IpAddressShort).SingleOrDefault()
If locInfo IsNot Nothing Then
Theoretically, if I'm correct, if there is no Session("Item1") set/if Session("Item1") is empty, then the rest of the snippet should run and set those variables.How come this isn't setting those variables on the first time the page load?
I'm planning to use some session variables on an intranet ASP/VB.NET page, and want to make sure that I'm not missing out on anything important I should know, or that I have my information mixed up. So here's what I (think) I know about session variables.They:are stored on the server, so if I have a lot of users then they'll each be using some more memory which could lead to a slowdown.are inaccessible by the user unless I expose access. hang around/persist across user requests (i.e. each time the user makes a request from the page the data will still be there - until it times out). This also means that I need to make sure that the variable doens't have "left over" data in it.
Is there anything that I've got totally wrong, or anything I'm missing? I'd prefer not to get bitten by a bug down the road because I think I understand what's going on.
I have a gridview and use a session to pass the variables from the page to an edit page. This works perfectly, until you search for a number. When you search the correct record displays in gridview, but when you click edit, it passes the wrong record.
Private Sub gridview1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Session("wr_id") = GridView1.Rows(e.NewEditIndex).Cells(2).Text & "~/~" & _ GridView1.Rows(e.NewEditIndex).Cells(3).Text & "~/~" & _ GridView1.Rows(e.NewEditIndex).Cells(4).Text & "~/~" & _ [Code] .....
I realize not all of the code is pasted in here, because it would take too much space. Any Ideas? I'm guessing it has something to do with e.NewEditIndex
After the client finishes testing, they go to the results page and then my program returns them back to the secondary page.If they re-enter the testing page again, for a second go-around, with out completely leaving the program as I have been doing since I was tweaking the code after each run, the repetition counter is not resting back to Zero. Itï¿½s still retains the information from the previous testing phase.
Example:The client chooses how many testing cycles they want to go through, from 1 to the total amount available to them to test. Right now its only 5.When they first start testing, it starts at ï¿½1 of 5ï¿½, then progresses at one increment for each drug they test on. Once they reach 5 and answer their final question, the program then goes to the results page and then to back the secondary page. If they choose to re-enter the testing page without totally leaving the program, the testing page counter sits at ï¿½5 of 5ï¿½. Shouldnï¿½t the page be resetting the variables each time it loads?
i am new to this. i have 4 pages. login.aspx, account.aspx, settings.aspx and fliers.aspx. its all programmed in vb.net with sql server backend.on my firstr page, login.aspx i have this code in the .vb page -
Dim SQL As String = "SELECT * FROM table1 WHERE email='" + Me.txtUserName.Text + "' AND password='" + Me.txtPassword.Text + "' " ExecuteNonQuery(SQL)
I have a datagridview and need to do some formatting to it. On load the row 0 column 0 cell is highlighted. I need users to click on datagridview to select a value. The issue is with the initial load highlight it looks like the first row is already selected when in fact it is now. How can this highlight be disabled? Each row of has 7 cell, the user is able to select any of the cell of a row and the corresponding row ID is selected. The issue is that only that one cell is highlighted.
I would like the entire row highlighted regardless of what cell in that row is clicked on. One of the columns is a status value. I would like to color the text based on the value. For example if the Status is opened I want the text to be red, if the status is closed the text color should be default.
I have an ASP.NET application that I am developing. I'm using session variables within the app.In Firefox & Chrome, they all work.But in IE (ver 9), there's one variable that's not working. I'm not sure if it's a storage or a retrieval (or both) at this point. The variable in question that I'm storing is a List(T) type. It's the only one of it's kind that I'm using. Can't help but think there's a correlation there.One other old post mentioned the possibility that cache is causing the problem, but I didn't understand the answer very well.
Dim Rec_IDs As New List(Of String) Rec_IDs = Session("Rec_IDs") and Dim Rec_IDs As New List(Of String)
I am using a sqlDataReader to get data and set it to session variables. The problem is it doesn't want to work with expressions. I can reference any other column in the table, but not the expressions. The SQL does work. The code is below.
I loading an array with data from my data base and then putting into a session Variable. I do not get any errors on that code. When I try to put the session Variable back into an array in my .aspx page I receive the following error message: [code]
I am trying to create an application similar to a quiz engine. I was wondering if I need session variables to store information between different pages or I can pull the data directly out of textboxes.I am using C-sharp,dot net and WPF.
I am trying to fix an ASP.NET application that is also written is VB and uses session variables to store the information from the logging page. In Firefox, the application runs just fine, but in IE (I am using IE 8), when I summit the logging credentials, the session variables become empty (takes me back to the logging pageThe weird thing is that when I move the privacy settings in IE (doesn't matter if high to low, or low to high) and enter the logging information again, the runs great. Also if I restart IIS 6.0 the application runs great. What's going on?
I am using this example I found to learn how to load class files and access variables through them. This is in a file called Class1.vb in the App_Code folder (this is not an app project):
Imports Microsoft.VisualBasic Public Class my_class Public Shared Sub my_sub()
How could I access the vartest variable without using a session, since if this is accessed by multiple functions at the same time the variable can be overwritten I assume. Is it possible to go the other way, where a variable is sent to a class file?
I've got a problem losing session variables in an ASP/VB.NET application. The application allows searching for an item or it can show an item if provided with a unique link (in the browser). It holds information about the item in session variables. In the webpage showing an Item a user can click a button which opens a window with additional information about the item - obtained from a session variable. When I search for the item using the search engine and click the button - it works OK.
When I copy the link to a browser: the item is shown, however clicking the button returns a 'null exception' - the session variables with information about the item are lost. Moreover when I provide the link for the second time the button works, the variables are there!
I have a web application that allows a user to view family members.
When the user clicks on a family member, it displays the member's basic info. There is also a grid displaying that family member's related family members. (e.g. User can click on the Father link. From that popup, they can then click on the Father's Father link, then click on the Father's Father's Grandson link, etc.).
To reduce the number of popups that appear on the screen, I want to prevent the user from continually clicking on family links past three members.
What is the best way to keep track on how many data forms have popped up? Or can this reliably be done with a web application?
Is there a way to set session variables during login that are then available to reports? We have a reporting services server where we move and denormalize data from our transaction system for reporting purposes. In order to allow our users to login with the same user name and password from the transactional system we have set up custom forms authentication and after much trial and error it is finally working. In addition we have the authorization accessing our transactional system so that any changes in user authority is immediately reflected in Reporting Services.
Our problem now is that we would like to add some additional features such as locking down parameters depending on user authority/groups in our transactional system. We have found a way to do it but it's inefficient, basically we have stored procedures that will query our transactional system to check for access. The problem is that these queries will often be run for every report request even though the answer is unlikely to change. It would be nice to have access to session level data that can be set once during log in and then accessed from the reports.
Does anyone know why a Page_Load would be called twice on a page when requesting an aspx page?I am using .Net 2.0 with the new .net 1.1 compilation model installed. Whenever I request a page, the Page_Load on the aspx page appears to be called twice, so does the Page_Load on and user controls added to that page.
I want a rich text box to display public variables like (pizza toppings links etc that have been selected in other forms) these variables have declare in a module. But I want the rich text box to display these variables as soon as the screen loads ( a on form load event) if you know what I mean.
I am using ASP.NET. It is possible to create a session variable on page load just for a particular page/url? The problem that I have is: The user comes to page 1 and the session variable becomes A, then he opens page 2 in a new tab and the session variable because B on both page 1 and page 2. So when the user needs the session variable on page 1 it does not work because the variable have changed!
I have a small application shared by 5 users. The application uses an Access 2007 database located on a local network server. My question is: Whenever a user logs into I save it's connection status on a table. When using OleDb is there a way of getting something like a unique "session id" for the user logging in?
I have a login page that return the userName to a page called User.aspx.The User.aspx shows the information about the user based on a sql select. I fill 12 labels on the page with the result of the select.I want to keep the information of my 12 labels if the user Quits and enter again in the page.I save my session
Session("UserPage") = (litHello.Text And litAddresse.Text And litAnimalGenre.Text And litCouriel.Text And litNomAnimal.Text And litPays.Text And litPostalCode.Text And litProvince.Text And litRace.Text And litTel.Text And litVille.Text)
Now how I can proceed too fill all my label with my saved session call UserPage??
If my sessions time out I want to re-direct the page to another URL: Say the home page. On my page I make use of a GridView that uses Session variables. If the session variable time expire(currently at 60min) and the user click on a row in the GridView I want to re-direct him/her to the home page of my site.
Using a session variable in my VB.net site has been figured out just fine. I just need to get my welcome message to stay put on every page. I put the code and text box in my master page to allow the message to stay there, but my label with the user's name disappears when I click on a different page.
The session is still there because I have it set up to display the textbox to enter your code if the session is destroyed or not available for some reason.
my code is not allowing the First_Name and Last_Name of the user's session to show up? The problem is in the Page_Load but I thought I would throw in the whole master.vb file to show everything I have so far.
Partial Class MasterPage Inherits System.Web.UI.MasterPage Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
I have 2 web pages. In the first webpage I have a text box which takes an user input.The number of controls rendered in the second page is based on the user input in the first page.I am storing the user input from the first page as a session variable [code]Now, I wish to use this session variable in the next page for initializing a global variable and what I tried to do is Dim num_Invitees As Integer = CType (Session("NoOfControls ToGenerate"),Integer)But this gives me a NullReferenceException.Can someone please suggest me what exactly I should be doing in order to use the session variable to initialize a global variable and also why the session variable's value is null while using outside a function but works fine when used inside a function?
I'm developing web site using asp.net. In my web site after login i set session for the logged user for my web site need. and on each page i checked whether that session is null or having value and depending on the value i redirected to the login page.My issue is that after login i want to redirect to the previously browsed web page and i done it by using following way-code on the particular page for checking session value-
I have set up a class as a facade to access the session variables for my app. In this app I store an entire dataset for a particular employer as a session variable.Within one of the sub pages I have a button that adds a row to an existing table stored in that dataset.
Dim curRow As Data.DataRow = mySession.tWorksiteOtherMeasures.NewRow() curRow("lngWorksiteID") = getSelectedWorksiteID(getSelectedSiteID()) curRow("strMeasure") = "" curRow("lngStatusID") = -1
When in the code to add the row the row count increments and the row exists. Once out of that scope the page refreshes due to the button being contained in an updatePanel. When that happens and I click the add button again the row counts for that item reset to 0 and 1 after the code runs. The previous added row is gone.Here is how the Dataset is assigned from the web service:
Public Shared Sub loadDSEmployer(ByVal strUserId As String) Dim myService As New someservice.service mySession.dsEmployer = myService.GetEmployerAndSites(strUserId, isInternal) End Sub
When I click the browser back button to go back to the page it says the page has expired. the other pages on my web site work and call the page load, the only solution i found but cant use is to wrp the whole page in an update panel, but i cant do this becuase i have a report viewer on the page that does not work with ajax.
I have a page to which i send some variables with the GET method. In my VB back-end i get those variables using Page.Request.QueryString("<name>")If i then use the IsNumeric method to make shure it is an numeric string i get True back as value.
When i then try to transform the string to an Integer using val, cÃ¬nt, Integer.Parse or cType I get an error saying that my string could not be converted to a integer.So i made an error page which gives me all the info i need to deal with the problem (view below) Exception Message: Conversion from string "" to type 'Integer' is not valid.
IsNumeric confirms that it is a numeric string and that it should be convertable to an Integer. So why won't it work. I don't think that my code should provide any extra information because it only gets the querystrings, uses IsNumeric and then tries to convert them.
I have a page that add Items to RadioButtonList with this code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) RD.Read() RBQ1.Items.Add(RD.GetString(3))
When I click in any button in the same page, the entire page reload and it display 8 items in the RadioButtonList, If I click for the second time I get 12 items in the RBL...How can I prevent the page to reload if I click in this button. ?
I am using <%@ MasterType virtualpath="~/__.Master" %> to embed my master page content into child page to access control belong to Master Page. I have one DropDownList in Master page. And I want to access its SelectedValue in my Child Page.
Problem is when page first time loads and as I am trying to access DropDownList's Selected Value by writing in child Page - "Master.DropDownList.SelectedValue". I am not able to get DropDownList's Value. Its display's Blank.
But When Page.IsPostBack I am able to get SelectedValue of that DropDownList.
I am storing an array of a custom serializable class in session on my site. When a page on the site changes, suddenly it renders them invalid, and tells me that it can't cast the type to it's own type. I assume the class version numbers are changing or something?!
I'm not trying to redesign this whole process.
Unable to cast object of type 'ShipmentPackages' to type 'ShipmentPackages'.
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'ShipmentPackages' to type 'ShipmentPackages'.
I can't get is to save variables permanently. For instance, say you run your project and in the source code you have Button1_click s=textbox1.text (s is the variable I declared) Button2_click s=label1.text. Say you type some thing into textbox1 then click button1. Then you click button2. Is it possible to make it that the next time you run the program the text you typed into textbox1.text last time is displayed when you click button2? I am using windows form.
Im studying vb coding at the moment and im designing a reasonably small text based game using the windows console and so far i have a nice working game but the main problem is that the game restarts when you end the console, obvious i know. Been trawling through pages looking at different ways to save multiple variables for multiple uses such as a save/load feature and most pages have confused me, people asking for help with commands im not common with. So far i've tried using my settings to save the variables in a test program but can't get it to work?I have in settings a variable called gold with a scope of user as an integer and i have this code to try and utilise it