VB .Net WebProject Variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dkalsow

    #1

    VB .Net WebProject Variables

    I am new to VB.Net WebProjects but have written VB.Net Projects for sometime. I am having problems with variables in my WebProjets. I dim them and I can use them but they do not keep there value. I have a timer that runs and each time the time if fired that value in the variable is back to what it was the time before, even though I have added 1 to it. Does any one have any idea why this is?

    Thanks in advance.

    Dale
  • One Handed Man \( OHM - Terry Burns \)

    #2
    Re: VB .Net WebProject Variables

    Where are you dimming this variable ?, dont forget once the page has been
    rendered, the page object is unloaded on the server

    Consider using the Session object to store this information in.

    Session.Add(Key ,Value)


    Having said all that, the right place to ask these questions in on ASPNET
    newsgroup.

    microsoft.publi c.dotnet.framew ork.aspnet



    Regards - OHM ( Terry Burns )




    "dkalsow" <dkalsow@discus sions.microsoft .com> wrote in message
    news:036E73D4-EAA3-4053-AC37-C13E95A67821@mi crosoft.com...[color=blue]
    > I am new to VB.Net WebProjects but have written VB.Net Projects for[/color]
    sometime. I am having problems with variables in my WebProjets. I dim them
    and I can use them but they do not keep there value. I have a timer that
    runs and each time the time if fired that value in the variable is back to
    what it was the time before, even though I have added 1 to it. Does any one
    have any idea why this is?[color=blue]
    >
    > Thanks in advance.
    >
    > Dale[/color]


    Comment

    • Cor Ligthert

      #3
      Re: VB .Net WebProject Variables

      > Having said all that, the right place to ask these questions in on ASPNET[color=blue]
      > newsgroup.
      >
      > microsoft.publi c.dotnet.framew ork.aspnet[/color]

      Why, has this to do installing the framework on the ASPNET server or has it
      to do with using the VB.language in a webform application?

      Cor


      Comment

      • One Handed Man \( OHM - Terry Burns \)

        #4
        Re: VB .Net WebProject Variables

        Well, unless I have mistaken this, the OP is designing an ASP.NET
        application. ServerControls reside on the IIS server, so the Framework has
        to already be installed there.

        Perhaps I just dont understand your question Cor.

        Regards ( OHM - Terry Burns )

        "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
        news:%23y5sj8gU EHA.2972@TK2MSF TNGP12.phx.gbl. ..[color=blue][color=green]
        > > Having said all that, the right place to ask these questions in on[/color][/color]
        ASPNET[color=blue][color=green]
        > > newsgroup.
        > >
        > > microsoft.publi c.dotnet.framew ork.aspnet[/color]
        >
        > Why, has this to do installing the framework on the ASPNET server or has[/color]
        it[color=blue]
        > to do with using the VB.language in a webform application?
        >
        > Cor
        >
        >[/color]


        Comment

        • Cor Ligthert

          #5
          Re: VB .Net WebProject Variables

          Hi Terry,

          It was in past often that when it was a little bit web, that the sentence
          came in this newsgroup to have a look at aspnet. It can be because in the
          German newsgroups there is as well an ASPNET entwickler (develloper)
          newsgroup.

          In my opinion is there not much difference when you are develloping for a
          Windowservice, a windowform, a webform, a webservice, a windowclass or
          whatever using Visual Studio Net.

          For a Webform is the special thing as you stated in your answer, however for
          the rest is beside using special controls almost nothing what is not the
          same.

          And therefore did you give in my opinion the right VB language answer,
          although for this because it is so small was the alternative maybe the
          viewstate maybe as well posible.

          Therefore I think that when it has to do with the VB language this is the
          right newsgroup, and now with your renewed expirience even more.

          :-)

          Cor


          Comment

          • One Handed Man \( OHM - Terry Burns \)

            #6
            Re: VB .Net WebProject Variables

            Hi Cor,
            Using ViewState will not work in this scenario, the reason
            being that the Post will reset the ViewState even if its being changed with
            a TimerClick on the server side. However, Session variables can be asjusted
            by the timer.

            See the following code to demonstrate. ( Assumes a Submit button present )
            Note that the following code is using viewstate ( as you suggested ). Run it
            this way first and see the results. Then comment out the ViewState lines and
            use the session Key/Value Pairs in the Session object, and try submitting
            again. You will see the counter is counting on the server while time
            elapses. Submiting button will produces variable and increasing numbers
            depening on the time lag.

            Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load
            'Put user code to initialize the page here
            Timer1.Interval = 1000
            Timer1.Start()

            If Page.IsPostBack Then
            'Response.Write (Session.Item(" C"))
            Response.Write( ViewState("C"))
            Else
            'Session.Add("C ", 1)
            ViewState.Add(" C", 1)
            End If

            End Sub

            Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
            System.Timers.E lapsedEventArgs ) Handles Timer1.Elapsed
            'Session.Item(" C") += 1
            Viewstate("C") += 1
            End Sub
            End Class


            Hope that makes it clear.

            Regards - OHM ( Terry Burns )



            "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
            news:enPgyohUEH A.704@TK2MSFTNG P09.phx.gbl...[color=blue]
            > Hi Terry,
            >
            > It was in past often that when it was a little bit web, that the sentence
            > came in this newsgroup to have a look at aspnet. It can be because in the
            > German newsgroups there is as well an ASPNET entwickler (develloper)
            > newsgroup.
            >
            > In my opinion is there not much difference when you are develloping for a
            > Windowservice, a windowform, a webform, a webservice, a windowclass or
            > whatever using Visual Studio Net.
            >
            > For a Webform is the special thing as you stated in your answer, however[/color]
            for[color=blue]
            > the rest is beside using special controls almost nothing what is not the
            > same.
            >
            > And therefore did you give in my opinion the right VB language answer,
            > although for this because it is so small was the alternative maybe the
            > viewstate maybe as well posible.
            >
            > Therefore I think that when it has to do with the VB language this is the
            > right newsgroup, and now with your renewed expirience even more.
            >
            > :-)
            >
            > Cor
            >
            >[/color]


            Comment

            • Cor Ligthert

              #7
              Re: VB .Net WebProject Variables

              Hi Terry,

              I changed your program, and that shows it even more, was for me it was
              amazing. The system timer goes on and set the referenced object in the
              session (and that can of course not in the viewstate).

              I did not really look what was the problem when I wrote the first message,
              however I saw something pointing on stateless and the session.

              Thanks for letting me know, I did not know this.

              However, this even shows more the truth from my other messages in this
              thread.

              :-)

              Cor

              \\\ beside the button it needs now 2 labels.
              Private WithEvents timer1 As New System.Timers.T imer
              Private Sub Page_Load(ByVal sender As System.Object, _
              ByVal e As System.EventArg s) Handles MyBase.Load
              'Put user code to initialize the page here
              If Page.IsPostBack Then
              Label1.Text = Session.Item("C ").ToString
              Label2.Text = ViewState("C"). ToString
              Else
              timer1.Interval = 1000
              timer1.Start()
              Session.Add("C" , 1)
              ViewState.Add(" C", 1)
              End If
              End Sub
              Private Sub Timer1_Elapsed( ByVal sender As System.Object, _
              ByVal e As System.Timers.E lapsedEventArgs ) Handles timer1.Elapsed
              Session.Item("C ") = CInt(Viewstate( "C")) + 1
              Viewstate.Item( "C") = CInt(Viewstate( "C")) + 1
              End Sub
              ///


              Comment

              Working...