State Management :: Declare A Variable In Page Load{} As Global?
Jan 2, 2011i want to declare a variable in page load{} as global so that i can monitor it so that it is not recreated each time
View 4 Repliesi want to declare a variable in page load{} as global so that i can monitor it so that it is not recreated each time
View 4 RepliesI'm looking for a way to declare a global variable (so all pages could see) but personal (so if one user puts some value in it, it won't matter to another user or change his value).Sessions and hidden fields won't do. I've tried working with declaring keys in Web.config but unfortunely, the keys values aren't personal, and all users share the same key value.Another way I was thinking was maybe classes, but perhaps there might be an easier solution?
View 19 RepliesI have to define a global and unchangeable variable in a web page. I used static variable but its content is the same for all users that use the page and it is bad. I dont want use Session variable.
View 5 RepliesI added the following code to global.asax to load up several session variable when a session starts. I'm assuming that when a page goes to use the variable that I should be
1) checking at the page level that the value is valid not 0 when its not expected to be 0, not a zero-length string when its expected to have a length
2) have code at the page level that sets the values if the values have not been set as when the Session timeout, ideally putting the code in a class derived from Page and then deriving all of my pages from the new class so that the code does not have to be repeated in every page
[Code]....
I've began working with asp.net mvc very recently and I've ran into a problem.I've got an aspx page which renders a few ascx pages. What I'd like to do is declare a global var at the aspx page so it is visible to all its childs. I tried <% var i = 0; %> but it wasn't visible at the child pages. What could I do?
View 4 Replieshow to declare global variable in master page and use it in all pages
View 1 RepliesI need to keep a global variable throughout the whole time the user is at my site, but do I use Application or a static class? The string variable should store a region name and my site makes a few changes depending on which region that has been set.
I read that Application was mainly for classic ASP, but I also read that a static class cannot be instantiated at runtime (e.g. when the user has logged in).
So, have I got something wrong here and which solution do I use?
Not sure if this was the forum to post under but here goes. I want to make a global variable counter that I can adjust in my code in the webforms. For example, I want to use the counter like so...
[Code]....
If anyone knows how to create this dynamic global variable or if anyone can tell me if its not possible,If it is not possible,
I would like know how to declare a global variable that can be used within a user after the user login and before the user logout across all the possible pages.
I need to develop a web application that will connect to 5 different servers depends on the selection of user on what server they wish to connect and after they select a server and login...I will need to keep track the server name in a variable last until the user logout (user may visit various pages but the server name MUST NOT be changed due to other user login into different server). So how can I do it so that other users may select different servers and will keep the server name for each different users.
Let says:-
User A selects Server A and login and User B selects Server B and login at the same time, so how the global variable can handle the needs for each user (User A & B) with different server select?
Is "Session" the only way to fulfill the above? I think of using Application State but it seems that the value stored will be shared by all users and not for a particular user.
How to declare a global variable or a public sub in a web application that all aspx pages can have access to?
View 5 RepliesI am having problems in retaining the string variable which I defined on the top of my scoop, everytime when page loads the string value becomes null. below is the snippet of the code:
public partial class Caravan_For_Sale : System.Web.UI.Page
{
string check;
PagedDataSource pds = new PagedDataSource(); //paging
[Code]....
The string check becomes null everytime when the dlPaging_ItemCommand becomes active(page loads).
When i start the application, based on some condition in global.asax page,i wil redirect to login page.If i click the logout button,
there i vil be clear all session value. here i want to initiate new session value like Session["InitialLogin"]="Yes".
How can i get this value in global .asax page. If get that session value [i.e Session["InitialLogin"]="Yes"], i vil redirect to some other page.
I cant able to get session value in global.asax page.i always getting null value.
I have created a matser page with a two radio buttons, text box and a button. Whenever user sets some values to these control and clicks the button, i will navigating him from one content page to another based on the data he has entered. The problem is after the content page load, the values selected/given in the controls(radio button, text box) are getting cleared.
Is there some way to maintain the values ?
can we grab a global variable or Session or View State variable in the javascript or using jquery?
want to use the value of a variable on to the other page, what i am supposed to do for that.i am novice at asp.net
View 8 RepliesIDE: MS Visual Studio 2008 / SQL Server 2005 Express / SQL Server Management Studio Express 2005
Skills: Beginner
Well im trying to make a custom login page(im not using ASP.net Login Control), in Admin.aspx page
UserName and Pasword are entered in textboxes , then Code-Behind file checks the UserName and Pasword against DataBase(it stores the UserName and Pasword) if both are correct Session["IsAuthenticated"] = "true" and then user is redirected to AdminArea.aspx
AdminArea.aspx checks if ( Session["IsAuthenticated"].ToString() == "false" ) then redirect to Error page..
but i get NullReferenceException on AdminArea.aspx because Session["IsAuthenticated"] is null , i dont know why ?
I even tried PreviousPage.Session["IsAuthneticated"] but still got the same error..
I debugged,and found out Admin.aspx saves value in Session["IsAuthenticated"] succesfully but AdminArea.aspx looses the Session["IsAuthenticated"]..so it gets null
My Question is how to retain value in Session["IsAuthenticated"] when page is changed (I want to retrieve value in next page from Session)?
i'm a asp.net c# beginner, i set a session variable in a.aspx but it's null when i try to retrieve it in b.aspx
I want to show my data in next page with well formated in table.I all ready write code for session which show data in next page.but i want to show it in table format and i also want to comapre in database for a price and show too. this is my code for next page:
[Code]....
this code show me data but as i say iwant it in table format and want to comapare session varibles in database i want to show price accoding that particular product. The Pervious page code:
[Code]....
I have a session variable which contains a list of elements. The user defines filters, which are sent to the Database, which fills the object with the elements that match. Then, that list is shown in a table. The code goes something like this:
[Code]....
Inside that page there is a button, which sends the request given the user filters. The Server creates the object and the session variable is assigned a value.
[Code]....
It works when the user sets the filters. However, given that once done it, the session variable has a value, I don't understand why if you navigate to other pages, the table doesn't appear when you return, given that:
1. It works when you perform the query and reload the page
2. The Session variable should be set for the rest of the session
I'm working on a web page that is going to be used to enter data into a database. The page is going to be dynamic in that the user has the ability to add a row to the table with the same fields, ie lname1, fname1, mi1 then lname2, fname2, mi2
I'm wanting to use a variable to keep track of how many lines there are so that when I generate the added line I am creating a new field with the ID of lname+# . Whats the best way to do this, a global variable, session variable? As side note, first time programming in .Net or C#.
I want to transfer a variable to another page when a button is clicked. I include the html code in label.text.
Source code is as follows:
MyLabel.Text += "<button type="button" onclick="location.href='a.aspx?oid='+this.oid"><b>Detail</b></button>";
oid is the variable that I want to transfer.However, It says "http://localhost:61884 OBJ_Browser.aspx?oid=undefined" when I click this button.
how I can transfer the value of oid to another page?
I am trying to set a session variable in the global.asax file and keep running into the problem that the Session is null.
I am running my application in VS2008 and using asp.net 3.51.
Here is my code:
1. In my web.config file I have enabled the session state and added the following line;
<sessionState
cookieless="false"
mode="InProc"
timeout="60"
></sessionState>
2. In the Session_Start procedure in the Global.asax file I set the session variable to a default value.
[Code]....
My problem seems to be that when the Application_Error procedure is executed the session state is lost.
Does anyone know why the session state isn't available in the Global.asax file.
I have a script that loads diferent photo in same div on masterpage for diferent pages.
So my question is how can I know what page is currently loaded so I can use something like this:
onpageload...
Dim pageID as String
pageID = ?????????
If pageID = "default1.aspx" Then
image1.ImageUrl = "~/zagreb.jpg"
ElseIf pageID = "default2.aspx" Then
image1.ImageUrl = "~/split.jpg"
End If
maybe I can put some kind of ID on every page but how?
HTTPresponse does not help to much becouse links looks diferent every time (default.aspx?sasa , default.aspx876786 .....)
I am using a FormView and on insert I want it to be redirected to another page and take the ID of the FormView which I have just inserted so I can have page b load with the date from page a that I have just inserted
View 3 RepliesHere is my scenario.In default.aspx page user selects the country, state, city from drop down list, and store them in cache for further use. but when other user open the web site from other computer it shows the same country, state, and city selected by user 1. Is there any problem related to cache? I have stored data as following.
cache["ctryID"] = ctryID;
cache["stateID"]= stateID;
cache["cityID"]= cityID;
I want to show default country, state , city at page load of default.aspx