473,587 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Total Field Problem

JJ
Hi,

I have a textbox setup on a web form and it suppose to keep a running
total of some other textboxs on page. In code behind I have a global double
var that is suppose to collect the total but doesn't work.

Here's what it looks like:

In global area I have:
protected double RegTot = 0.0;
In Method I have:
RegTot += RegTot + TextBox1.value;

when ever I change TextBox1.value, RegTot is always zero. So I only get the
present value in textbox1 and never any previous values that should be in
RegTot. How should I code this so I can collect the values in Textbox1
multiple times and store in RegTot for a final amount? This is not in a table
or datagrid.

Thanks,

JJ
Nov 19 '05 #1
2 1048
JJ wrote:
Here's what it looks like:

In global area I have:
protected double RegTot = 0.0;
In Method I have:
RegTot += RegTot + TextBox1.value;

when ever I change TextBox1.value, RegTot is always zero. (abriged)

ASP.NET doesn't maintain the object state between postbacks. To preserve
the value of RegTot you'll have to store it in the view state or in a
session variable.

To store the value in and retrieve it from the view state do this:
if (Page.IsPostBac k) {
// Read from view state
RegTot=Convert. ToDouble(ViewSt ate["RegTot"]);
} else {
// Store in view state
ViewState["RegTot"] = RegTot;
}

To store the value in and retrieve it from session do this:
if (Page.IsPostBac k) {
// Read from session
RegTot=Convert. ToDouble(Sessio n["RegTot"]);
} else {
// Store in session
Session["RegTot"] = RegTot;
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #2
JJ
Hi Anders,

I was wondering also I had built a separate class to store the Running
Total for page but It would do the same thing and return zero for previous
value entered.
So the class doesn't persist for the life of the page I assume?

Thanks for replying,

JJ
"Anders Norås [MCAD]" wrote:
JJ wrote:
Here's what it looks like:

In global area I have:
protected double RegTot = 0.0;
In Method I have:
RegTot += RegTot + TextBox1.value;

when ever I change TextBox1.value, RegTot is always zero. (abriged)

ASP.NET doesn't maintain the object state between postbacks. To preserve
the value of RegTot you'll have to store it in the view state or in a
session variable.

To store the value in and retrieve it from the view state do this:
if (Page.IsPostBac k) {
// Read from view state
RegTot=Convert. ToDouble(ViewSt ate["RegTot"]);
} else {
// Store in view state
ViewState["RegTot"] = RegTot;
}

To store the value in and retrieve it from session do this:
if (Page.IsPostBac k) {
// Read from session
RegTot=Convert. ToDouble(Sessio n["RegTot"]);
} else {
// Store in session
Session["RegTot"] = RegTot;
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/

Nov 19 '05 #3

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

Similar topics

1
10806
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. So how do I change this script so that I can call any field or any number of fields to be totaled? For example - calculate(myfield01, myfield02) at...
2
4977
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I haven't found a way to do this. I tried <span style="width:20em"> <input type="text"> <img width="25px" src="...">
0
5276
by: Matt | last post by:
I am running CR 8.5 from a (large) SQL Server db. My aim is to use crystal enterprise so end users in our sales team can access reports on demand for a given date range and client so I am trying to keep contact with the database to a minimum. IE currently processign a report takes about 10 minutes and involves manually running stored procs...
2
5639
by: phaddock4 | last post by:
Please help. GOAL: I hope to calculate a total amount in a TotalQuery (or field in the SubQuery?), based upon three field amounts in a SubQuery. STATUS: When I create an expression in the TotalQuery based upon SubQuery fields, e.g: Total: + +
4
1423
by: mukeshhtrivedi | last post by:
I have TYPE field which has 3 data like HEAD, TRACK and PANEL. Now whenever any person works on HEAD we put 8 Hrs in HRS filed and in LABOR field it reflects the dollar value automatically like $160 (8*20=160).Now I want to display the total of Head, Track and Panel in following; Actual Cost for Head: (All head total should display here if...
2
2315
by: Jana | last post by:
Using Access 97. Background: I have a main report called rptTrustHeader with a subreport rptTrustDetails in the Details section of the main report. The main report is grouped by MasterClientID. There are also several other subreports in the main report's footer. The rptTrustDetails subreport has two grouping levels MasterClientID and...
7
3644
by: Sunil Korah | last post by:
Hi, I haven't used access reports much. I have a problem in getting the total of a group. I have 3 fields, ProgName (Program name), Pname (Participant's name) and PCategory (Participant category) PCategory can have values 'SC', 'ST' and 'Others'
3
2589
by: voroojak | last post by:
hi I have a such abig problem. i have to disable the shortcut keys (table, query, report, .....) except form. the user should just be able to open form and all other the shortcut should be disable. i have one more problem and that is i want to disable my total field. i eman teh user cant enter any data in total fields. my total field is...
7
2136
by: Ecohouse | last post by:
I'm working on a project that was dropped in my lap. It is in Access 2003. There are short time fields which get calculated values (eg. 1:30). But I will need to total up those values for reports in qiueries. When I tried to drop one of the fields in the query builder and used the total function the totals was way off. So I was...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.