C# Variable Passing Question

Status
Not open for further replies.

Baez

Admin / Dev
Staff member
Messages
6,990
Location
Toronto, Canada
Hey guys starting to learn a little C# now that I'm a C/C++ guru!

I'm writing some code that will increment/decrement a labels value depending on the radio button clicked in a list. The problem I'm having is that I don't want it to increment if I click on a radio with a value of 30 when going from a radio with a value of 40 the first time. It should go down by 10. But of course it doesn't save any variables with postback.

This is my code so far: test.txt

So if you could give any suggestions on how to save the last value in my "Prev" function that would be great.
 
You should be using a private field to store your value rather than relying on a method call (which is what a property really is) to convert a string to an int every time you access the value. In your case, you may want two fields -- _value and _oldValue. In your increment/decrement methods, check to see if you should increment/decrement by one or 10.
 
I am a C# developer by profession, but I am not an ASP developer. Unless a new object is created before each Page_Load method is executed, the value of a class variable will remain unchanged. The easiest way to find out is to try it and see what happens.
 
Status
Not open for further replies.
Back
Top Bottom