473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Losing Variable

I'm using ASP.net and SQL Server.
I declare a Public Variable. I then set it depending on a if then else
statement below. My problem is because of the various round trips to the
server I lose the value of that variable by the time I need it.
Public CurrentStatus As Integer HERE IS WHERE I SET IT

If dtRealtor.Rows.Count <> 0 Then HERE IS WHERE I GIVE IT SOMETHING
CurrentStatus = 1
Else
CurrentStatus = 2
End If

Then when I call its value it equals 0 and I think its because of the server
round trips 0 it out.
Thank you,

Big E
Nov 18 '05 #1
2 1052
Ben
How are you maintaining the value? Are you putting it into viewstate or
anything like that? If I were you, I'd try placing the value into viewstate
in the page_render function and I'd read it from viewstate during page_init.
If the page_init is empty, you'll have to load it..

I code in c#, but maybe vb is similar...

CurrentStatus = ViewState("CurrentStatus")

If Page.IsPostBack Then
If CurrentStatus <> 1 Or CurrentStatus <> 2 Then
'you need to reload it...
End If
End If
Or something like that...

and to save it...

ViewState("CurrentStatus") = CurrentStatus
I'm guessing vb still uses () in c# it's []
ViewState["CurrentStatus"]

Sooo

int CurrentStatus = Convert.ToInt32(ViewState["CurrentStatus"]);

if (CurrentStatus != 1 || CurrentStatus !=2)
{
// currentstatus is invalid
}
"Big E" <no****@nospam.com> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
I'm using ASP.net and SQL Server.
I declare a Public Variable. I then set it depending on a if then else
statement below. My problem is because of the various round trips to the
server I lose the value of that variable by the time I need it.
Public CurrentStatus As Integer HERE IS WHERE I SET IT

If dtRealtor.Rows.Count <> 0 Then HERE IS WHERE I GIVE IT SOMETHING
CurrentStatus = 1
Else
CurrentStatus = 2
End If

Then when I call its value it equals 0 and I think its because of the server round trips 0 it out.
Thank you,

Big E


Nov 18 '05 #2
Variables like you have declared are only good for the lifetime of the page cycle. When the page is done executing, they go away.

You need to store the variable in a container that doesn't go away at the end of each page request. ViewState, or Session for example.
"Big E" <no****@nospam.com> wrote in message news:ec**************@TK2MSFTNGP11.phx.gbl...
I'm using ASP.net and SQL Server.
I declare a Public Variable. I then set it depending on a if then else
statement below. My problem is because of the various round trips to the
server I lose the value of that variable by the time I need it.
Public CurrentStatus As Integer HERE IS WHERE I SET IT

If dtRealtor.Rows.Count <> 0 Then HERE IS WHERE I GIVE IT SOMETHING
CurrentStatus = 1
Else
CurrentStatus = 2
End If



Then when I call its value it equals 0 and I think its because of the server
round trips 0 it out.


Thank you,

Big E

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott Lyon | last post by:
I'm maintaining (read: I didn't write it, nor do I have the time to spend to rewrite it) an application that is suddenly giving me grief. The reason I say suddenly, is because we're in the...
2
by: James | last post by:
Session("UserName") is set when someone logs in. Get to a page that displays a record where you can type a comment. The form has an onSubmit event that calls a javascript function. That function...
6
by: Colleyville Alan | last post by:
I seem to recall reading somewhere that there was a keyword that allowed a variable to have data added to it without losing its contents. a = "Hi " and b = "There" myvar = a myvar = b the...
4
by: Stephen | last post by:
I have a .NET (1.1 framework) application that is losing a session variable on only a few PC's. The main page is loading up in a frame in a Portal application. On the Page_Load it stores an...
4
by: Keith-Earl | last post by:
I have been writing ASP.NET apps since the RTM build and have never seen this. I built a simple app that uses session variables on my DEV laptop. All runs well. I have a simple toggle routine...
9
by: Adrian Parker | last post by:
We have a website that works everywhere but on a few PCs on this one site.. Asp.Net 1.1 Server = Windows 2003 Client = XP In the web.config we use - cookieless="false" in the browser settings...
0
by: Frank Bishop | last post by:
Can someone tell me why I'm losing my session variable when using Response.Redirect? When I use the RedirectFromLoginPage method(currently remmed out below), my session variable works fine, but I'm...
0
by: Jimmy Reds | last post by:
Hi, Sorry if this appears twice but I post through Google Groups and it had a funny 5 minutes and didn't appear to post this message the first time. I am setting session variables on a page...
2
by: Jimmy Reds | last post by:
Hi, I am setting session variables on a page then doing a header/location redirect to a second page however I am losing one of my session variables. Not all of them, just one. Here are some...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.