-
lifetime of variables
Hi can someone help me
I declare a variable to a certain value in the form.aspx.vb page an then
run the application, then I push a serverbutton to reload the page and give
a new value to the variable. but every time I reload the page it is set to
the first value. Does a variable not keep the value ? I thought the object
was alive until session ends.
Dim currentItem As Integer 'this is the dim section at top
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnNext.Click
currentItem = currentItem + 1
txtData.Text = currentItem 'here it is 1 everyme i reload the page
End Sub
Peter
-
Re: lifetime of variables
See
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcontrolexecutionlifecycle.asp for the lifecycle.
What about
txtData.Text=CLng(txtDate.Text)+1 ?
--
"Peter" <vb.@127.0.0.1> a écrit dans le message de news:
3edf0f4d$1@tnews.web.devx.com...
>
>
> Hi can someone help me
> I declare a variable to a certain value in the form.aspx.vb page an then
> run the application, then I push a serverbutton to reload the page and
give
> a new value to the variable. but every time I reload the page it is set to
> the first value. Does a variable not keep the value ? I thought the object
> was alive until session ends.
>
> Dim currentItem As Integer 'this is the dim section at top
>
> Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
> Handles btnNext.Click
> currentItem = currentItem + 1
> txtData.Text = currentItem 'here it is 1 everyme i reload the page
> End Sub
>
> Peter
>
>
-
Re: lifetime of variables
Thanks but..
txtData.text is still 0 when i have reloaded the page. The only way I can
think about is using a session variable.....and it works, I have tried, but
I still wonder if that's the only way?
Peter
"Patrice Scribe" <scribe@chez.com> wrote:
>See
>http://msdn.microsoft.com/library/de...us/cpguide/htm
>l/cpconcontrolexecutionlifecycle.asp for the lifecycle.
>
>What about
>
>txtData.Text=CLng(txtDate.Text)+1 ?
>
>--
>
>"Peter" <vb.@127.0.0.1> a écrit dans le message de news:
>3edf0f4d$1@tnews.web.devx.com...
>>
>>
>> Hi can someone help me
>> I declare a variable to a certain value in the form.aspx.vb page an then
>> run the application, then I push a serverbutton to reload the page and
>give
>> a new value to the variable. but every time I reload the page it is set
to
>> the first value. Does a variable not keep the value ? I thought the object
>> was alive until session ends.
>>
>> Dim currentItem As Integer 'this is the dim section at top
>>
>> Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs)
>> Handles btnNext.Click
>> currentItem = currentItem + 1
>> txtData.Text = currentItem 'here it is 1 everyme i reload the
page
>> End Sub
>>
>> Peter
>>
>>
>
-
Re: lifetime of variables
> The only way I can think about is using a session variable...
> and it works, I have tried, but I still wonder if that's the
> only way?
Peter: It's not the only way. You can also use ViewState, or the Cache
object, or a cookie, or a hidden form field, or a QueryString value, or a
database. But you need to save the value somewhere and pass it back with the
next request, otherwise your code has no way of knowing that the subsequent
request is related in any way to the previous one.
You may find the following articles helpful:
http://www.fawcette.com/dotnetmag/20...online/bolges/
http://www.softartisans.com/softarti...per-utley.html
--
Phil Weber
-
Re: lifetime of variables
On the web you start fresh with each request but ASP.NET is able to gives
the "illusion of continuity".
Check out the viewstate property of the "txtData" control. The framework
should be able to automatically save/restore the control value (of course it
can't do this automatically for plain old variables). Make sure also to
initialize the value if needed.
--
"Peter" <vb.@127.0.0.1> a écrit dans le message de news:
3edf379b$1@tnews.web.devx.com...
>
> Thanks but..
> txtData.text is still 0 when i have reloaded the page. The only way I can
> think about is using a session variable.....and it works, I have tried,
but
> I still wonder if that's the only way?
>
> Peter
>
> "Patrice Scribe" <scribe@chez.com> wrote:
> >See
>
>http://msdn.microsoft.com/library/de...-us/cpguide/ht
m
> >l/cpconcontrolexecutionlifecycle.asp for the lifecycle.
> >
> >What about
> >
> >txtData.Text=CLng(txtDate.Text)+1 ?
> >
> >--
> >
> >"Peter" <vb.@127.0.0.1> a écrit dans le message de news:
> >3edf0f4d$1@tnews.web.devx.com...
> >>
> >>
> >> Hi can someone help me
> >> I declare a variable to a certain value in the form.aspx.vb page an
then
> >> run the application, then I push a serverbutton to reload the page and
> >give
> >> a new value to the variable. but every time I reload the page it is set
> to
> >> the first value. Does a variable not keep the value ? I thought the
object
> >> was alive until session ends.
> >>
> >> Dim currentItem As Integer 'this is the dim section at top
> >>
> >> Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
> >System.EventArgs)
> >> Handles btnNext.Click
> >> currentItem = currentItem + 1
> >> txtData.Text = currentItem 'here it is 1 everyme i reload the
> page
> >> End Sub
> >>
> >> Peter
> >>
> >>
> >
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks