473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable not incrementing

Hello,

I am using Visual Web Developer and decared a Public Variable in the Class
section. I assigned a value in the load section, and on a button I set it
up to increment, but it always delivers the same value, 1. When I increment
the variable from the button, shouldn't it hold the new value? I also
tried declaring the variable as a Friend, but it wasn't any more friendly.
;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class
Mar 13 '06 #1
10 1451
HTTP is stateless. This means on every request to the server, a new Page
object is created. Since it is always a new object, whatever values you set
on the old object, will not persist.

However, even if everything worked as you imagine with there being one
instance of a Page object all the time, your code would still not run as
expected. This is because you are always setting i to 0 in Page_Load. So
after the user clicks the button, i would be set to 0, then incremented by 1
in the click handler. Then on the next click the same thing would happen,
and i would always be at 1.

However, even if you fix your code to only set it to 0 in Page_Load when
it's not a postback (or just not do anything, since 0 is the default for an
integer anyway), your code would not work as you expect for the reasons
given in the beginning of the post.

I recommend you get a book on ASP.NET and do some reading about how it all
works before proceeding much further. Without an understand of the page
lifecycle and the basic mechanics of ASP.NET it will be hard to get far.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am using Visual Web Developer and decared a Public Variable in the Class
section. I assigned a value in the load section, and on a button I set it
up to increment, but it always delivers the same value, 1. When I
increment the variable from the button, shouldn't it hold the new value?
I also tried declaring the variable as a Friend, but it wasn't any more
friendly. ;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class

Mar 13 '06 #2
But you must remember that in the client/server model of the web, each time
you request this web page, a BRAND NEW instance of this class is created and
your variable is created again, from scratch. You aren't continuing with
the same page class instance the second time you use the page.

You must store your variable in a more persistant location, such as a
cookie, the cache, viewstate or a database to be able to reuse it across
page calls.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am using Visual Web Developer and decared a Public Variable in the Class
section. I assigned a value in the load section, and on a button I set it
up to increment, but it always delivers the same value, 1. When I
increment the variable from the button, shouldn't it hold the new value?
I also tried declaring the variable as a Friend, but it wasn't any more
friendly. ;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class

Mar 13 '06 #3
Thank you Marina. You are right about not understanding what is happening.
Here is why I am not following. I placed a textbox on the same form using
the same button, and was able to increment the value in the textbox. The
code is below:
Partial Class test
Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load

'i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

'i = i + 1

'MsgBox(i, MsgBoxStyle.Inf ormation)

TextBox1.Text = TextBox1.Text + 1

End Sub

End Class
If the page refreshes each time I click the button, then why doesn't the
textbox lose its value? Maybe I'm not making sense, but its how I see it.
;)

God Bless,

Mark

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
HTTP is stateless. This means on every request to the server, a new Page
object is created. Since it is always a new object, whatever values you
set on the old object, will not persist.

However, even if everything worked as you imagine with there being one
instance of a Page object all the time, your code would still not run as
expected. This is because you are always setting i to 0 in Page_Load. So
after the user clicks the button, i would be set to 0, then incremented by
1 in the click handler. Then on the next click the same thing would
happen, and i would always be at 1.

However, even if you fix your code to only set it to 0 in Page_Load when
it's not a postback (or just not do anything, since 0 is the default for
an integer anyway), your code would not work as you expect for the reasons
given in the beginning of the post.

I recommend you get a book on ASP.NET and do some reading about how it all
works before proceeding much further. Without an understand of the page
lifecycle and the basic mechanics of ASP.NET it will be hard to get far.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am using Visual Web Developer and decared a Public Variable in the
Class section. I assigned a value in the load section, and on a button I
set it up to increment, but it always delivers the same value, 1. When I
increment the variable from the button, shouldn't it hold the new value?
I also tried declaring the variable as a Friend, but it wasn't any more
friendly. ;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class


Mar 14 '06 #4
That's because Textboxes (as well as many of the Web Forms Controls)
maintain their own state like this:

When data is posted to the server, that data becomes the DEFAULT value of
the control as it is sent back down to the browser. Now, when the browser
sends that data back up to the server, the server uses this data as the
starting point from which to work. No data is actually being stored
(persisted) on the server.

A good analogy of how client/server works:

When you look up at the stars at night, you are seeing what they looked like
in the past. For all you know, the star you are looking at doesn't even
exist anymore.

When you look at a web page (nice segway, huh?), you are seeing the RESULTS
of some server processing, but by the time you see those results, the server
has disconnected from you and moved on to handle someone else's request.
None of your data is stored on the server. If you re-submit the page you
are looking at in your browser, the server must create a brand new instance
of a page class, place band new instances of controls on this page and
attempt to restore certain controls back to their previous values. Of
course, the server doesn't have any of these previous values, so it is up to
the client to post those values up to the server. That's what's happening
with your textbox example.

The ONLY way to persist data on the server is to store that data somewhere
that the server can get a hold of it. As I mentioned in my last reply:
ViewState, the Cache, a database, cookies, a flat file, etc. are all good
candidates.

As Marina suggested, a good understanding of client/server communication as
well as a good understanding of the Page class's life-cycle would be a good
place to start.

Good luck,

Scott

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you Marina. You are right about not understanding what is
happening. Here is why I am not following. I placed a textbox on the same
form using the same button, and was able to increment the value in the
textbox. The code is below:
Partial Class test
Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

'i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

'i = i + 1

'MsgBox(i, MsgBoxStyle.Inf ormation)

TextBox1.Text = TextBox1.Text + 1

End Sub

End Class
If the page refreshes each time I click the button, then why doesn't the
textbox lose its value? Maybe I'm not making sense, but its how I see it.
;)

God Bless,

Mark

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
HTTP is stateless. This means on every request to the server, a new Page
object is created. Since it is always a new object, whatever values you
set on the old object, will not persist.

However, even if everything worked as you imagine with there being one
instance of a Page object all the time, your code would still not run as
expected. This is because you are always setting i to 0 in Page_Load. So
after the user clicks the button, i would be set to 0, then incremented
by 1 in the click handler. Then on the next click the same thing would
happen, and i would always be at 1.

However, even if you fix your code to only set it to 0 in Page_Load when
it's not a postback (or just not do anything, since 0 is the default for
an integer anyway), your code would not work as you expect for the
reasons given in the beginning of the post.

I recommend you get a book on ASP.NET and do some reading about how it
all works before proceeding much further. Without an understand of the
page lifecycle and the basic mechanics of ASP.NET it will be hard to get
far.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am using Visual Web Developer and decared a Public Variable in the
Class section. I assigned a value in the load section, and on a button
I set it up to increment, but it always delivers the same value, 1.
When I increment the variable from the button, shouldn't it hold the
new value? I also tried declaring the variable as a Friend, but it
wasn't any more friendly. ;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class



Mar 14 '06 #5
Hello Scott,

I understand what you are saying, but I don't understand why this is any
different than using Access VBA or another language in a client server
setting. If the data doesn't persist on the server, it is becuase noone
addressed that issue? I have an analogy about visual studio... It is like
putting a Peterbilt body, a Cummins engine, and an Eaton Transmission onto a
horse drawn wagon. Why not rebuild the chassis while you're (meaning
Microsoft) at it. ;)

God Bless,

Mark

"Scott M." <s-***@nospam.nosp am> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
That's because Textboxes (as well as many of the Web Forms Controls)
maintain their own state like this:

When data is posted to the server, that data becomes the DEFAULT value of
the control as it is sent back down to the browser. Now, when the browser
sends that data back up to the server, the server uses this data as the
starting point from which to work. No data is actually being stored
(persisted) on the server.

A good analogy of how client/server works:

When you look up at the stars at night, you are seeing what they looked
like in the past. For all you know, the star you are looking at doesn't
even exist anymore.

When you look at a web page (nice segway, huh?), you are seeing the
RESULTS of some server processing, but by the time you see those results,
the server has disconnected from you and moved on to handle someone else's
request. None of your data is stored on the server. If you re-submit the
page you are looking at in your browser, the server must create a brand
new instance of a page class, place band new instances of controls on this
page and attempt to restore certain controls back to their previous
values. Of course, the server doesn't have any of these previous values,
so it is up to the client to post those values up to the server. That's
what's happening with your textbox example.

The ONLY way to persist data on the server is to store that data somewhere
that the server can get a hold of it. As I mentioned in my last reply:
ViewState, the Cache, a database, cookies, a flat file, etc. are all good
candidates.

As Marina suggested, a good understanding of client/server communication
as well as a good understanding of the Page class's life-cycle would be a
good place to start.

Good luck,

Scott

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you Marina. You are right about not understanding what is
happening. Here is why I am not following. I placed a textbox on the
same form using the same button, and was able to increment the value in
the textbox. The code is below:
Partial Class test
Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

'i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

'i = i + 1

'MsgBox(i, MsgBoxStyle.Inf ormation)

TextBox1.Text = TextBox1.Text + 1

End Sub

End Class
If the page refreshes each time I click the button, then why doesn't the
textbox lose its value? Maybe I'm not making sense, but its how I see
it. ;)

God Bless,

Mark

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
HTTP is stateless. This means on every request to the server, a new Page
object is created. Since it is always a new object, whatever values you
set on the old object, will not persist.

However, even if everything worked as you imagine with there being one
instance of a Page object all the time, your code would still not run as
expected. This is because you are always setting i to 0 in Page_Load. So
after the user clicks the button, i would be set to 0, then incremented
by 1 in the click handler. Then on the next click the same thing would
happen, and i would always be at 1.

However, even if you fix your code to only set it to 0 in Page_Load when
it's not a postback (or just not do anything, since 0 is the default for
an integer anyway), your code would not work as you expect for the
reasons given in the beginning of the post.

I recommend you get a book on ASP.NET and do some reading about how it
all works before proceeding much further. Without an understand of the
page lifecycle and the basic mechanics of ASP.NET it will be hard to get
far.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am using Visual Web Developer and decared a Public Variable in the
Class section. I assigned a value in the load section, and on a button
I set it up to increment, but it always delivers the same value, 1.
When I increment the variable from the button, shouldn't it hold the
new value? I also tried declaring the variable as a Friend, but it
wasn't any more friendly. ;)

Partial Class test

Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

i = i + 1

MsgBox(i, MsgBoxStyle.Inf ormation)

End Sub

End Class



Mar 14 '06 #6
To address your questions/comments.

HTTP client/server is not at all how programming Access with VBA works.
Access VBA programs are client only, not client/server (unless you put the
Access DB on a shared server, in which case it is client/server, but not
HTTP client/server - so the comparison is still not valid).

As for data not persisting on the server, it is not Visual Studio or
Microsoft's fault, this is the very nature of HTTP and the WWW. This is by
design and is not a glitch or a bug. It is to facilitate the hundreds of
millions of clients out there connecting to the (somewhat smaller by
comparison) millions of servers out there. A server just can't keep a
dedicated connection open to each client that wants it. If it did, then
we'd all be getting "busy signals" quite often when we try to visit any web
site.

In short, HTTP client/server is just a different architecture than client
only because of the distributed nature of the Internet. Putting an Access
VBA application on a server doesn't make that architecture client/server in
the same sense because each client DOES have a continuous connection to the
server (and tying up precious resources as well). Imagine if 1,000 (just to
use a very small number for demonstration purposes) people tried to get at
your VBA application at the same time. How about 1,000,000? Wouldn't it
make sense to only be connected to the user for just the time it takes to
process their request, and free up the database for someone else to use?

If you are going to do any web development at all (Microsoft .NET, Java
Server Pages, PHP, etc.) you must understand this concept well and also
understand that it is not something brought on by a vendor, it is the way
web development works regardless of platform or product.

Good luck,

-Scott
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
Hello Scott,

I understand what you are saying, but I don't understand why this is any
different than using Access VBA or another language in a client server
setting. If the data doesn't persist on the server, it is becuase noone
addressed that issue? I have an analogy about visual studio... It is like
putting a Peterbilt body, a Cummins engine, and an Eaton Transmission onto
a horse drawn wagon. Why not rebuild the chassis while you're (meaning
Microsoft) at it. ;)

God Bless,

Mark

"Scott M." <s-***@nospam.nosp am> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
That's because Textboxes (as well as many of the Web Forms Controls)
maintain their own state like this:

When data is posted to the server, that data becomes the DEFAULT value of
the control as it is sent back down to the browser. Now, when the browser
sends that data back up to the server, the server uses this data as the
starting point from which to work. No data is actually being stored
(persisted) on the server.

A good analogy of how client/server works:

When you look up at the stars at night, you are seeing what they looked
like in the past. For all you know, the star you are looking at doesn't
even exist anymore.

When you look at a web page (nice segway, huh?), you are seeing the
RESULTS of some server processing, but by the time you see those results,
the server has disconnected from you and moved on to handle someone
else's request. None of your data is stored on the server. If you
re-submit the page you are looking at in your browser, the server must
create a brand new instance of a page class, place band new instances of
controls on this page and attempt to restore certain controls back to
their previous values. Of course, the server doesn't have any of these
previous values, so it is up to the client to post those values up to the
server. That's what's happening with your textbox example.

The ONLY way to persist data on the server is to store that data
somewhere that the server can get a hold of it. As I mentioned in my
last reply: ViewState, the Cache, a database, cookies, a flat file, etc.
are all good candidates.

As Marina suggested, a good understanding of client/server communication
as well as a good understanding of the Page class's life-cycle would be a
good place to start.

Good luck,

Scott

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you Marina. You are right about not understanding what is
happening. Here is why I am not following. I placed a textbox on the
same form using the same button, and was able to increment the value in
the textbox. The code is below:
Partial Class test
Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

'i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

'i = i + 1

'MsgBox(i, MsgBoxStyle.Inf ormation)

TextBox1.Text = TextBox1.Text + 1

End Sub

End Class
If the page refreshes each time I click the button, then why doesn't the
textbox lose its value? Maybe I'm not making sense, but its how I see
it. ;)

God Bless,

Mark

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
HTTP is stateless. This means on every request to the server, a new
Page object is created. Since it is always a new object, whatever
values you set on the old object, will not persist.

However, even if everything worked as you imagine with there being one
instance of a Page object all the time, your code would still not run
as expected. This is because you are always setting i to 0 in
Page_Load. So after the user clicks the button, i would be set to 0,
then incremented by 1 in the click handler. Then on the next click the
same thing would happen, and i would always be at 1.

However, even if you fix your code to only set it to 0 in Page_Load
when it's not a postback (or just not do anything, since 0 is the
default for an integer anyway), your code would not work as you expect
for the reasons given in the beginning of the post.

I recommend you get a book on ASP.NET and do some reading about how it
all works before proceeding much further. Without an understand of the
page lifecycle and the basic mechanics of ASP.NET it will be hard to
get far.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uj******** ******@TK2MSFTN GP09.phx.gbl...
> Hello,
>
> I am using Visual Web Developer and decared a Public Variable in the
> Class section. I assigned a value in the load section, and on a
> button I set it up to increment, but it always delivers the same
> value, 1. When I increment the variable from the button, shouldn't it
> hold the new value? I also tried declaring the variable as a Friend,
> but it wasn't any more friendly. ;)
>
> Partial Class test
>
> Inherits System.Web.UI.P age
>
> Public i As Integer
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArg s) Handles Me.Load
>
> i = 0
>
> End Sub
>
> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
> System.EventArg s) Handles Button2.Click
>
> i = i + 1
>
> MsgBox(i, MsgBoxStyle.Inf ormation)
>
> End Sub
>
> End Class
>
>



Mar 14 '06 #7
Scott,

I'm not trying to give you hard time by disagreeing with you, but I do. ;)
I understand what you are saying about the nature of http and www, but I
believe that the internet can be exactly like a client server on a computer
network. If that is what Bill Gates wanted that is what would happen. Bill
runs the show. If he wanted to change the protocols of the internet and how
his browser worked, he could do it. For the most part, millions of people
don't concurrently access the bulk of websites. Maybe hundreds would be a
high number, so servers could in most cases handle the traffic. I think its
a matter of design. I have linked SQL Server tables to Access apps, on my
local machine, to a server in Atlanta, so I know the technology is there.
Its just a matter of "doing it right", which unfortunately is a Microsoft
weakpoint. It always falls short of the mark in all of its apps.

But that is just my opinion and I know it will anger a lot of Microsoft
devotees and I'm sorry for that. ;)

God Bless,

Mark
"Scott M." <s-***@nospam.nosp am> wrote in message
news:ei******** ******@TK2MSFTN GP09.phx.gbl...
To address your questions/comments.

HTTP client/server is not at all how programming Access with VBA works.
Access VBA programs are client only, not client/server (unless you put the
Access DB on a shared server, in which case it is client/server, but not
HTTP client/server - so the comparison is still not valid).

As for data not persisting on the server, it is not Visual Studio or
Microsoft's fault, this is the very nature of HTTP and the WWW. This is
by design and is not a glitch or a bug. It is to facilitate the hundreds
of millions of clients out there connecting to the (somewhat smaller by
comparison) millions of servers out there. A server just can't keep a
dedicated connection open to each client that wants it. If it did, then
we'd all be getting "busy signals" quite often when we try to visit any
web site.

In short, HTTP client/server is just a different architecture than client
only because of the distributed nature of the Internet. Putting an Access
VBA application on a server doesn't make that architecture client/server
in the same sense because each client DOES have a continuous connection to
the server (and tying up precious resources as well). Imagine if 1,000
(just to use a very small number for demonstration purposes) people tried
to get at your VBA application at the same time. How about 1,000,000?
Wouldn't it make sense to only be connected to the user for just the time
it takes to process their request, and free up the database for someone
else to use?

If you are going to do any web development at all (Microsoft .NET, Java
Server Pages, PHP, etc.) you must understand this concept well and also
understand that it is not something brought on by a vendor, it is the way
web development works regardless of platform or product.

Good luck,

-Scott
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
Hello Scott,

I understand what you are saying, but I don't understand why this is any
different than using Access VBA or another language in a client server
setting. If the data doesn't persist on the server, it is becuase noone
addressed that issue? I have an analogy about visual studio... It is
like putting a Peterbilt body, a Cummins engine, and an Eaton
Transmission onto a horse drawn wagon. Why not rebuild the chassis while
you're (meaning Microsoft) at it. ;)

God Bless,

Mark

"Scott M." <s-***@nospam.nosp am> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
That's because Textboxes (as well as many of the Web Forms Controls)
maintain their own state like this:

When data is posted to the server, that data becomes the DEFAULT value
of the control as it is sent back down to the browser. Now, when the
browser sends that data back up to the server, the server uses this data
as the starting point from which to work. No data is actually being
stored (persisted) on the server.

A good analogy of how client/server works:

When you look up at the stars at night, you are seeing what they looked
like in the past. For all you know, the star you are looking at doesn't
even exist anymore.

When you look at a web page (nice segway, huh?), you are seeing the
RESULTS of some server processing, but by the time you see those
results, the server has disconnected from you and moved on to handle
someone else's request. None of your data is stored on the server. If
you re-submit the page you are looking at in your browser, the server
must create a brand new instance of a page class, place band new
instances of controls on this page and attempt to restore certain
controls back to their previous values. Of course, the server doesn't
have any of these previous values, so it is up to the client to post
those values up to the server. That's what's happening with your
textbox example.

The ONLY way to persist data on the server is to store that data
somewhere that the server can get a hold of it. As I mentioned in my
last reply: ViewState, the Cache, a database, cookies, a flat file, etc.
are all good candidates.

As Marina suggested, a good understanding of client/server communication
as well as a good understanding of the Page class's life-cycle would be
a good place to start.

Good luck,

Scott

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you Marina. You are right about not understanding what is
happening. Here is why I am not following. I placed a textbox on the
same form using the same button, and was able to increment the value in
the textbox. The code is below:
Partial Class test
Inherits System.Web.UI.P age

Public i As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

'i = 0

End Sub

Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click

'i = i + 1

'MsgBox(i, MsgBoxStyle.Inf ormation)

TextBox1.Text = TextBox1.Text + 1

End Sub

End Class
If the page refreshes each time I click the button, then why doesn't
the textbox lose its value? Maybe I'm not making sense, but its how I
see it. ;)

God Bless,

Mark

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
> HTTP is stateless. This means on every request to the server, a new
> Page object is created. Since it is always a new object, whatever
> values you set on the old object, will not persist.
>
> However, even if everything worked as you imagine with there being one
> instance of a Page object all the time, your code would still not run
> as expected. This is because you are always setting i to 0 in
> Page_Load. So after the user clicks the button, i would be set to 0,
> then incremented by 1 in the click handler. Then on the next click the
> same thing would happen, and i would always be at 1.
>
> However, even if you fix your code to only set it to 0 in Page_Load
> when it's not a postback (or just not do anything, since 0 is the
> default for an integer anyway), your code would not work as you expect
> for the reasons given in the beginning of the post.
>
> I recommend you get a book on ASP.NET and do some reading about how it
> all works before proceeding much further. Without an understand of the
> page lifecycle and the basic mechanics of ASP.NET it will be hard to
> get far.
>
> "Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
> news:uj******** ******@TK2MSFTN GP09.phx.gbl...
>> Hello,
>>
>> I am using Visual Web Developer and decared a Public Variable in the
>> Class section. I assigned a value in the load section, and on a
>> button I set it up to increment, but it always delivers the same
>> value, 1. When I increment the variable from the button, shouldn't
>> it hold the new value? I also tried declaring the variable as a
>> Friend, but it wasn't any more friendly. ;)
>>
>> Partial Class test
>>
>> Inherits System.Web.UI.P age
>>
>> Public i As Integer
>>
>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>> System.EventArg s) Handles Me.Load
>>
>> i = 0
>>
>> End Sub
>>
>> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
>> System.EventArg s) Handles Button2.Click
>>
>> i = i + 1
>>
>> MsgBox(i, MsgBoxStyle.Inf ormation)
>>
>> End Sub
>>
>> End Class
>>
>>
>
>



Mar 15 '06 #8
Mark,

You are entitled to your opinion, but what we are discussing here isn't
opinion based.

FACT: The Internet and the World Wide Web are not goverened by Microsoft.
If anything, it is goverened by The World Wide Web Consortium. When software
manufacturers wish to use the Internet in a different way, they make
different software. Instant Messaging is a good example of this. When you
use an instant messanger product (from AOL, MS, Yahoo, or anyone else), your
message is travelling over the Internet, but NOT via HTTP. And, because
different software manufacturers come up with their own protocols that are
proprietary, you run into compatibility issues between software. Try IM-ing
a MSN Messanger user via AOL's AIM - not going to happen! On the other hand
you can use different email software clients to send/recieve email because
email (all email) travels using the mailto: protocol - - it's a standard.

FACT: HTTP is the Internet's web server protocol. HTTP was not invented,
nor is it goverened by any software manufacturer. It is a standard protocol
that the WWW is designed to run on. You can't just up and change it or the
WWW would collapse.

Now, to address your specific comments...see inline below:

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OC******** ********@TK2MSF TNGP11.phx.gbl. ..
Scott,

I'm not trying to give you hard time by disagreeing with you, but I do. ;)
I understand what you are saying about the nature of http and www, but I
believe that the internet can be exactly like a client server on a
computer network.
On who's network? Would that network run NETBIOS, NETBUI or some other
protocol? And what if one application on one network wanted to communicate
with another application on another network, but the two networks run on
different protocols?

What you are suggesting would only be possible if there were standard
protocols that everyone's software understood and only if the network could
support millions of simultaneous connections. Perhaps one day, but not
today.
If that is what Bill Gates wanted that is what would happen. Bill runs
the show. If he wanted to change the protocols of the internet and how
his browser worked, he could do it.
ROFLMAO: I'm sorry, but a statement like this just tells me that you really
don't have an understanding of how things *actually* work. There are
countless initives that Bill and MS pushed hard over the years, that wound
up in the garbage because the rest of the world didn't agree. Can you say
"MS Bob"?
For the most part, millions of people don't concurrently access the bulk
of websites. Maybe hundreds would be a high number, so servers could in
most cases handle the traffic.
What source do you get this information from? I'd say that is flat out not
true at all. And, even if it were true, many (millions...not hundreds)
sites DO experience millions of hits per day. So, shouldn't the network be
set up in a way that can handle the highest possible volumne, not the
lowest?
I think its a matter of design.
Yes. You are 100% absolutlely correct. The Internet was absolutley designed
like this intentionally and it works quite well. Just because you have to
change your client programming mentality doesn't make HTTP client/server bad
or wrong...just different.
I have linked SQL Server tables to Access apps, on my local machine, to a
server in Atlanta, so I know the technology is there.
And, what was the highest volume your applicaiton ever had to deal with?
With this, I think you've hit the nail on the head. No one is saying that
*all* applications must be HTTP based. In your situation, you found a
solution that worked for you. It's just that on the world's largest
network, that isn't how things are done. The network MUST be able to handle
extremely high volumes of traffic that come from different platforms and
from different software. That design specification can only mandate one
thing: STANDARDS. HTTP is that standard.
Its just a matter of "doing it right", which unfortunately is a Microsoft
weakpoint. It always falls short of the mark in all of its apps.
Again, I fail to understand why you are blaming Microsoft for something that
wasn't designed, built or tested by anyone from MS. In fact, the Internet
and its fundamental protocol, TCP/IP, was created before there even was a
Microsoft (mid 1960's by the Defense Advanced Research Projects Agency or
DARPA). The WWW was created by Tim Berners-Lee, who is now the President of
the World Wide Web Consortium (which is not accountable to any software
vendor).
But that is just my opinion and I know it will anger a lot of Microsoft
devotees and I'm sorry for that. ;)
It's not a matter of angering any MS devotees. It's a matter of you not
understanding how the system is built or who built it as well as how and
why it was built that way. That's not my opinion. Based on your
statements, it is clear that you need to go back and try to understand the
very nature of the Internet before you apply non-truths to it.

Good luck,

-Scott


God Bless,

Mark
"Scott M." <s-***@nospam.nosp am> wrote in message
news:ei******** ******@TK2MSFTN GP09.phx.gbl...
To address your questions/comments.

HTTP client/server is not at all how programming Access with VBA works.
Access VBA programs are client only, not client/server (unless you put
the Access DB on a shared server, in which case it is client/server, but
not HTTP client/server - so the comparison is still not valid).

As for data not persisting on the server, it is not Visual Studio or
Microsoft's fault, this is the very nature of HTTP and the WWW. This is
by design and is not a glitch or a bug. It is to facilitate the hundreds
of millions of clients out there connecting to the (somewhat smaller by
comparison) millions of servers out there. A server just can't keep a
dedicated connection open to each client that wants it. If it did, then
we'd all be getting "busy signals" quite often when we try to visit any
web site.

In short, HTTP client/server is just a different architecture than client
only because of the distributed nature of the Internet. Putting an
Access VBA application on a server doesn't make that architecture
client/server in the same sense because each client DOES have a
continuous connection to the server (and tying up precious resources as
well). Imagine if 1,000 (just to use a very small number for
demonstration purposes) people tried to get at your VBA application at
the same time. How about 1,000,000? Wouldn't it make sense to only be
connected to the user for just the time it takes to process their
request, and free up the database for someone else to use?

If you are going to do any web development at all (Microsoft .NET, Java
Server Pages, PHP, etc.) you must understand this concept well and also
understand that it is not something brought on by a vendor, it is the way
web development works regardless of platform or product.

Good luck,

-Scott
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
Hello Scott,

I understand what you are saying, but I don't understand why this is any
different than using Access VBA or another language in a client server
setting. If the data doesn't persist on the server, it is becuase noone
addressed that issue? I have an analogy about visual studio... It is
like putting a Peterbilt body, a Cummins engine, and an Eaton
Transmission onto a horse drawn wagon. Why not rebuild the chassis
while you're (meaning Microsoft) at it. ;)

God Bless,

Mark

"Scott M." <s-***@nospam.nosp am> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
That's because Textboxes (as well as many of the Web Forms Controls)
maintain their own state like this:

When data is posted to the server, that data becomes the DEFAULT value
of the control as it is sent back down to the browser. Now, when the
browser sends that data back up to the server, the server uses this
data as the starting point from which to work. No data is actually
being stored (persisted) on the server.

A good analogy of how client/server works:

When you look up at the stars at night, you are seeing what they looked
like in the past. For all you know, the star you are looking at
doesn't even exist anymore.

When you look at a web page (nice segway, huh?), you are seeing the
RESULTS of some server processing, but by the time you see those
results, the server has disconnected from you and moved on to handle
someone else's request. None of your data is stored on the server. If
you re-submit the page you are looking at in your browser, the server
must create a brand new instance of a page class, place band new
instances of controls on this page and attempt to restore certain
controls back to their previous values. Of course, the server doesn't
have any of these previous values, so it is up to the client to post
those values up to the server. That's what's happening with your
textbox example.

The ONLY way to persist data on the server is to store that data
somewhere that the server can get a hold of it. As I mentioned in my
last reply: ViewState, the Cache, a database, cookies, a flat file,
etc. are all good candidates.

As Marina suggested, a good understanding of client/server
communication as well as a good understanding of the Page class's
life-cycle would be a good place to start.

Good luck,

Scott

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Thank you Marina. You are right about not understanding what is
> happening. Here is why I am not following. I placed a textbox on the
> same form using the same button, and was able to increment the value
> in the textbox. The code is below:
> Partial Class test
> Inherits System.Web.UI.P age
>
> Public i As Integer
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArg s) Handles Me.Load
>
> 'i = 0
>
> End Sub
>
> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
> System.EventArg s) Handles Button2.Click
>
> 'i = i + 1
>
> 'MsgBox(i, MsgBoxStyle.Inf ormation)
>
> TextBox1.Text = TextBox1.Text + 1
>
> End Sub
>
> End Class
>
>
> If the page refreshes each time I click the button, then why doesn't
> the textbox lose its value? Maybe I'm not making sense, but its how I
> see it. ;)
>
> God Bless,
>
> Mark
>
>
>
>
>
> "Marina Levit [MVP]" <so*****@nospam .com> wrote in message
> news:eL******** ******@TK2MSFTN GP12.phx.gbl...
>> HTTP is stateless. This means on every request to the server, a new
>> Page object is created. Since it is always a new object, whatever
>> values you set on the old object, will not persist.
>>
>> However, even if everything worked as you imagine with there being
>> one instance of a Page object all the time, your code would still not
>> run as expected. This is because you are always setting i to 0 in
>> Page_Load. So after the user clicks the button, i would be set to 0,
>> then incremented by 1 in the click handler. Then on the next click
>> the same thing would happen, and i would always be at 1.
>>
>> However, even if you fix your code to only set it to 0 in Page_Load
>> when it's not a postback (or just not do anything, since 0 is the
>> default for an integer anyway), your code would not work as you
>> expect for the reasons given in the beginning of the post.
>>
>> I recommend you get a book on ASP.NET and do some reading about how
>> it all works before proceeding much further. Without an understand of
>> the page lifecycle and the basic mechanics of ASP.NET it will be hard
>> to get far.
>>
>> "Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
>> news:uj******** ******@TK2MSFTN GP09.phx.gbl...
>>> Hello,
>>>
>>> I am using Visual Web Developer and decared a Public Variable in the
>>> Class section. I assigned a value in the load section, and on a
>>> button I set it up to increment, but it always delivers the same
>>> value, 1. When I increment the variable from the button, shouldn't
>>> it hold the new value? I also tried declaring the variable as a
>>> Friend, but it wasn't any more friendly. ;)
>>>
>>> Partial Class test
>>>
>>> Inherits System.Web.UI.P age
>>>
>>> Public i As Integer
>>>
>>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>>> System.EventArg s) Handles Me.Load
>>>
>>> i = 0
>>>
>>> End Sub
>>>
>>> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
>>> System.EventArg s) Handles Button2.Click
>>>
>>> i = i + 1
>>>
>>> MsgBox(i, MsgBoxStyle.Inf ormation)
>>>
>>> End Sub
>>>
>>> End Class
>>>
>>>
>>
>>
>
>



Mar 15 '06 #9
Hello Scott,

I don't want to drag this on. I understand your point of view and believe
what you say about the current state of the internet. I respect your
knowledge and ability and you are right, I don't understand the workings,
but I do believe they can be improved. Of course I'm a guy that thinks
evolution is silly nonsense. ;)

Thank you for your response.

God Bless,

Mark
"Scott M." <s-***@nospam.nosp am> wrote in message
news:ux******** ********@tk2msf tngp13.phx.gbl. ..
Mark,

You are entitled to your opinion, but what we are discussing here isn't
opinion based.

FACT: The Internet and the World Wide Web are not goverened by Microsoft.
If anything, it is goverened by The World Wide Web Consortium. When
software manufacturers wish to use the Internet in a different way, they
make different software. Instant Messaging is a good example of this.
When you use an instant messanger product (from AOL, MS, Yahoo, or anyone
else), your message is travelling over the Internet, but NOT via HTTP.
And, because different software manufacturers come up with their own
protocols that are proprietary, you run into compatibility issues between
software. Try IM-ing a MSN Messanger user via AOL's AIM - not going to
happen! On the other hand you can use different email software clients to
send/recieve email because email (all email) travels using the mailto:
protocol - - it's a standard.

FACT: HTTP is the Internet's web server protocol. HTTP was not invented,
nor is it goverened by any software manufacturer. It is a standard
protocol that the WWW is designed to run on. You can't just up and change
it or the WWW would collapse.

Now, to address your specific comments...see inline below:

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OC******** ********@TK2MSF TNGP11.phx.gbl. ..
Scott,

I'm not trying to give you hard time by disagreeing with you, but I do.
;) I understand what you are saying about the nature of http and www, but
I believe that the internet can be exactly like a client server on a
computer network.


On who's network? Would that network run NETBIOS, NETBUI or some other
protocol? And what if one application on one network wanted to
communicate with another application on another network, but the two
networks run on different protocols?

What you are suggesting would only be possible if there were standard
protocols that everyone's software understood and only if the network
could support millions of simultaneous connections. Perhaps one day, but
not today.
If that is what Bill Gates wanted that is what would happen. Bill runs
the show. If he wanted to change the protocols of the internet and how
his browser worked, he could do it.


ROFLMAO: I'm sorry, but a statement like this just tells me that you
really don't have an understanding of how things *actually* work. There
are countless initives that Bill and MS pushed hard over the years, that
wound up in the garbage because the rest of the world didn't agree. Can
you say "MS Bob"?
For the most part, millions of people don't concurrently access the bulk
of websites. Maybe hundreds would be a high number, so servers could in
most cases handle the traffic.


What source do you get this information from? I'd say that is flat out
not true at all. And, even if it were true, many (millions...not
hundreds) sites DO experience millions of hits per day. So, shouldn't the
network be set up in a way that can handle the highest possible volumne,
not the lowest?
I think its a matter of design.


Yes. You are 100% absolutlely correct. The Internet was absolutley
designed like this intentionally and it works quite well. Just because
you have to change your client programming mentality doesn't make HTTP
client/server bad or wrong...just different.
I have linked SQL Server tables to Access apps, on my local machine, to
a server in Atlanta, so I know the technology is there.


And, what was the highest volume your applicaiton ever had to deal with?
With this, I think you've hit the nail on the head. No one is saying that
*all* applications must be HTTP based. In your situation, you found a
solution that worked for you. It's just that on the world's largest
network, that isn't how things are done. The network MUST be able to
handle extremely high volumes of traffic that come from different
platforms and from different software. That design specification can only
mandate one thing: STANDARDS. HTTP is that standard.
Its just a matter of "doing it right", which unfortunately is a Microsoft
weakpoint. It always falls short of the mark in all of its apps.


Again, I fail to understand why you are blaming Microsoft for something
that wasn't designed, built or tested by anyone from MS. In fact, the
Internet and its fundamental protocol, TCP/IP, was created before there
even was a Microsoft (mid 1960's by the Defense Advanced Research Projects
Agency or DARPA). The WWW was created by Tim Berners-Lee, who is now the
President of the World Wide Web Consortium (which is not accountable to
any software vendor).
But that is just my opinion and I know it will anger a lot of Microsoft
devotees and I'm sorry for that. ;)


It's not a matter of angering any MS devotees. It's a matter of you not
understanding how the system is built or who built it as well as how and
why it was built that way. That's not my opinion. Based on your
statements, it is clear that you need to go back and try to understand the
very nature of the Internet before you apply non-truths to it.

Good luck,

-Scott


God Bless,

Mark
"Scott M." <s-***@nospam.nosp am> wrote in message
news:ei******** ******@TK2MSFTN GP09.phx.gbl...
To address your questions/comments.

HTTP client/server is not at all how programming Access with VBA works.
Access VBA programs are client only, not client/server (unless you put
the Access DB on a shared server, in which case it is client/server, but
not HTTP client/server - so the comparison is still not valid).

As for data not persisting on the server, it is not Visual Studio or
Microsoft's fault, this is the very nature of HTTP and the WWW. This is
by design and is not a glitch or a bug. It is to facilitate the
hundreds of millions of clients out there connecting to the (somewhat
smaller by comparison) millions of servers out there. A server just
can't keep a dedicated connection open to each client that wants it. If
it did, then we'd all be getting "busy signals" quite often when we try
to visit any web site.

In short, HTTP client/server is just a different architecture than
client only because of the distributed nature of the Internet. Putting
an Access VBA application on a server doesn't make that architecture
client/server in the same sense because each client DOES have a
continuous connection to the server (and tying up precious resources as
well). Imagine if 1,000 (just to use a very small number for
demonstration purposes) people tried to get at your VBA application at
the same time. How about 1,000,000? Wouldn't it make sense to only be
connected to the user for just the time it takes to process their
request, and free up the database for someone else to use?

If you are going to do any web development at all (Microsoft .NET, Java
Server Pages, PHP, etc.) you must understand this concept well and also
understand that it is not something brought on by a vendor, it is the
way web development works regardless of platform or product.

Good luck,

-Scott
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
Hello Scott,

I understand what you are saying, but I don't understand why this is
any different than using Access VBA or another language in a client
server setting. If the data doesn't persist on the server, it is
becuase noone addressed that issue? I have an analogy about visual
studio... It is like putting a Peterbilt body, a Cummins engine, and an
Eaton Transmission onto a horse drawn wagon. Why not rebuild the
chassis while you're (meaning Microsoft) at it. ;)

God Bless,

Mark

"Scott M." <s-***@nospam.nosp am> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
> That's because Textboxes (as well as many of the Web Forms Controls)
> maintain their own state like this:
>
> When data is posted to the server, that data becomes the DEFAULT value
> of the control as it is sent back down to the browser. Now, when the
> browser sends that data back up to the server, the server uses this
> data as the starting point from which to work. No data is actually
> being stored (persisted) on the server.
>
> A good analogy of how client/server works:
>
> When you look up at the stars at night, you are seeing what they
> looked like in the past. For all you know, the star you are looking
> at doesn't even exist anymore.
>
> When you look at a web page (nice segway, huh?), you are seeing the
> RESULTS of some server processing, but by the time you see those
> results, the server has disconnected from you and moved on to handle
> someone else's request. None of your data is stored on the server. If
> you re-submit the page you are looking at in your browser, the server
> must create a brand new instance of a page class, place band new
> instances of controls on this page and attempt to restore certain
> controls back to their previous values. Of course, the server doesn't
> have any of these previous values, so it is up to the client to post
> those values up to the server. That's what's happening with your
> textbox example.
>
> The ONLY way to persist data on the server is to store that data
> somewhere that the server can get a hold of it. As I mentioned in my
> last reply: ViewState, the Cache, a database, cookies, a flat file,
> etc. are all good candidates.
>
> As Marina suggested, a good understanding of client/server
> communication as well as a good understanding of the Page class's
> life-cycle would be a good place to start.
>
> Good luck,
>
> Scott
>
>
>
> "Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
> news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>> Thank you Marina. You are right about not understanding what is
>> happening. Here is why I am not following. I placed a textbox on the
>> same form using the same button, and was able to increment the value
>> in the textbox. The code is below:
>> Partial Class test
>> Inherits System.Web.UI.P age
>>
>> Public i As Integer
>>
>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>> System.EventArg s) Handles Me.Load
>>
>> 'i = 0
>>
>> End Sub
>>
>> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
>> System.EventArg s) Handles Button2.Click
>>
>> 'i = i + 1
>>
>> 'MsgBox(i, MsgBoxStyle.Inf ormation)
>>
>> TextBox1.Text = TextBox1.Text + 1
>>
>> End Sub
>>
>> End Class
>>
>>
>> If the page refreshes each time I click the button, then why doesn't
>> the textbox lose its value? Maybe I'm not making sense, but its how
>> I see it. ;)
>>
>> God Bless,
>>
>> Mark
>>
>>
>>
>>
>>
>> "Marina Levit [MVP]" <so*****@nospam .com> wrote in message
>> news:eL******** ******@TK2MSFTN GP12.phx.gbl...
>>> HTTP is stateless. This means on every request to the server, a new
>>> Page object is created. Since it is always a new object, whatever
>>> values you set on the old object, will not persist.
>>>
>>> However, even if everything worked as you imagine with there being
>>> one instance of a Page object all the time, your code would still
>>> not run as expected. This is because you are always setting i to 0
>>> in Page_Load. So after the user clicks the button, i would be set to
>>> 0, then incremented by 1 in the click handler. Then on the next
>>> click the same thing would happen, and i would always be at 1.
>>>
>>> However, even if you fix your code to only set it to 0 in Page_Load
>>> when it's not a postback (or just not do anything, since 0 is the
>>> default for an integer anyway), your code would not work as you
>>> expect for the reasons given in the beginning of the post.
>>>
>>> I recommend you get a book on ASP.NET and do some reading about how
>>> it all works before proceeding much further. Without an understand
>>> of the page lifecycle and the basic mechanics of ASP.NET it will be
>>> hard to get far.
>>>
>>> "Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
>>> news:uj******** ******@TK2MSFTN GP09.phx.gbl...
>>>> Hello,
>>>>
>>>> I am using Visual Web Developer and decared a Public Variable in
>>>> the Class section. I assigned a value in the load section, and on
>>>> a button I set it up to increment, but it always delivers the same
>>>> value, 1. When I increment the variable from the button, shouldn't
>>>> it hold the new value? I also tried declaring the variable as a
>>>> Friend, but it wasn't any more friendly. ;)
>>>>
>>>> Partial Class test
>>>>
>>>> Inherits System.Web.UI.P age
>>>>
>>>> Public i As Integer
>>>>
>>>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>>>> System.EventArg s) Handles Me.Load
>>>>
>>>> i = 0
>>>>
>>>> End Sub
>>>>
>>>> Protected Sub Button2_Click(B yVal sender As Object, ByVal e As
>>>> System.EventArg s) Handles Button2.Click
>>>>
>>>> i = i + 1
>>>>
>>>> MsgBox(i, MsgBoxStyle.Inf ormation)
>>>>
>>>> End Sub
>>>>
>>>> End Class
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Mar 15 '06 #10

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

Similar topics

10
2334
by: David Casey | last post by:
I'm working on a program for my C++ class and have it all written and working except for one part. I need to compare two numeric variables to determine decimal accuracy between them. For example: pi = 3.14159... mynum = 3.14226... The mynum is accurate to 2 decimal places compared to pi. I could figure this out easy with a char array since I could just take a character one at a time from each array and compare it. However with a...
4
2522
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add" button is clicked. In addition, the session variable is reset to zero when the "Empty" button is pressed. The problem is if the value is non-zero and the page is reloaded the value is incremented. It appears as if the "Add" onClick event...
5
2358
by: Daz | last post by:
Hello. Please could somebody explain to me a method for auto-incrementing a variable name? I need to append a number to the variable name as it's created as it will be automated. For example: blah1 blah2
8
1841
by: pozz | last post by:
In my software, there are some variables that represents some settings. They usually are numerical variables: unsigned char (0..255), signed char (-127..128), unsigned int (0..65535), signed int (-32767..32768). I want to write a generic C function that changes the value of one parameter. For example, a function that takes a pointer to the variable and increments it by one. Of course, the function doesn't know the variable type (unsigned...
3
3348
by: Elementary | last post by:
I have a number of variables, e.g. X1, X2, X3, X4, X5. I want to select only the ones that are non zero(there will only be 2 or 3 at any time), and record them as Y1, Y2 and Y3 I want to know the best way of incrementing the name of the variable, e.g. the variable in a loop is X + (num) I was trying Num1=1 Num2=1
0
9551
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10255
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7582
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
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
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.