Simple Pulbic Variable

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

    #1

    Simple Pulbic Variable

    I'm new. I have an aspx page and I want to declare a public variable
    "GroupID" at the top of the page and be able to change the value in
    different parts of that particular page. Bascially, how do you creat a
    public variable for one page only?
    Thanks!


  • Trevor Benedict

    #2
    Re: Simple Pulbic Variable

    If you want to use it within the page, declare it within the class
    definition
    like

    Private GroupID as Integer

    Regards,

    Trevor Benedict
    MCSD

    "pvong" <phillip*at*yah oo*dot*comwrote in message
    news:%23%23S16h UMIHA.1188@TK2M SFTNGP04.phx.gb l...
    I'm new. I have an aspx page and I want to declare a public variable
    "GroupID" at the top of the page and be able to change the value in
    different parts of that particular page. Bascially, how do you creat a
    public variable for one page only?
    Thanks!
    >

    Comment

    • pvong

      #3
      Re: Simple Pulbic Variable

      Perfect! Thanks!

      "Trevor Benedict" <TrevorNews@yah oo.comwrote in message
      news:OWtxi5UMIH A.2208@TK2MSFTN GP06.phx.gbl...
      If you want to use it within the page, declare it within the class
      definition
      like
      >
      Private GroupID as Integer
      >
      Regards,
      >
      Trevor Benedict
      MCSD
      >
      "pvong" <phillip*at*yah oo*dot*comwrote in message
      news:%23%23S16h UMIHA.1188@TK2M SFTNGP04.phx.gb l...
      >I'm new. I have an aspx page and I want to declare a public variable
      >"GroupID" at the top of the page and be able to change the value in
      >different parts of that particular page. Bascially, how do you creat a
      >public variable for one page only?
      >Thanks!
      >>
      >
      >

      Comment

      • pvong

        #4
        Re: Simple Pulbic Variable

        Is this by design....

        When I have an onclick of a control, it assigns the public variable a value.
        When I click on another control, the value is gone from the public variable?
        Am I not sticking the public variable in the right place. This is where I
        have it in my code behind...

        Imports System.Data, System.Data.Sql Client

        Partial Class Client_ClientMt gNote

        Inherits System.Web.UI.P age

        Public groupid As Integer

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




        "Trevor Benedict" <TrevorNews@yah oo.comwrote in message
        news:OWtxi5UMIH A.2208@TK2MSFTN GP06.phx.gbl...
        If you want to use it within the page, declare it within the class
        definition
        like
        >
        Private GroupID as Integer
        >
        Regards,
        >
        Trevor Benedict
        MCSD
        >
        "pvong" <phillip*at*yah oo*dot*comwrote in message
        news:%23%23S16h UMIHA.1188@TK2M SFTNGP04.phx.gb l...
        >I'm new. I have an aspx page and I want to declare a public variable
        >"GroupID" at the top of the page and be able to change the value in
        >different parts of that particular page. Bascially, how do you creat a
        >public variable for one page only?
        >Thanks!
        >>
        >
        >

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Simple Pulbic Variable

          pvong,

          A webpage is not persisitent, in other words, all information in the class
          will be destroyed at the moment that you send the page.

          To make things global for a page of a certain user there are 3 methods, for
          which in my idea the session.item is in most cases the most effective to
          use.

          Cor

          Comment

          • Mythran

            #6
            Re: Simple Pulbic Variable



            "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
            news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@mi crosoft.com...
            pvong,
            >
            A webpage is not persisitent, in other words, all information in the class
            will be destroyed at the moment that you send the page.
            >
            To make things global for a page of a certain user there are 3 methods,
            for which in my idea the session.item is in most cases the most effective
            to use.
            >
            Cor
            Session isn't for the one page only though, as the OP wants. Granted, he
            can get at it in the single page, but it is scoped for the entire session
            for all pages under a single site.

            OP:
            To store a value for the current user for the current page, you'd want to
            use something like the ViewState.

            ViewState("MyPr opertyName") = MyValue

            HTH,
            Mythran


            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Simple Pulbic Variable

              Mytrhan,

              The way you describe it can in my idea bemisunderstood . A session is for all
              pages, however not for all users. As long as you don't use an item on
              another page, then it is for one page.

              You describe in my idea in a way the status of a static class and the cache
              from ASP.NET. To a user belongs the session and the vieuwstate as you wrote.
              The session does not for nothing use the cookie.

              The problem with a viewstate is that it is transported over the InterNet and
              can make the transaction long.

              Cor

              "Mythran" <kip_potter@hot mail.comschreef in bericht
              news:7DA0D4ED-86EF-4EB8-A2F3-8B741416B603@mi crosoft.com...
              >
              >
              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
              news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@mi crosoft.com...
              >pvong,
              >>
              >A webpage is not persisitent, in other words, all information in the
              >class will be destroyed at the moment that you send the page.
              >>
              >To make things global for a page of a certain user there are 3 methods,
              >for which in my idea the session.item is in most cases the most effective
              >to use.
              >>
              >Cor
              >
              Session isn't for the one page only though, as the OP wants. Granted, he
              can get at it in the single page, but it is scoped for the entire session
              for all pages under a single site.
              >
              OP:
              To store a value for the current user for the current page, you'd want to
              use something like the ViewState.
              >
              ViewState("MyPr opertyName") = MyValue
              >
              HTH,
              Mythran
              >
              >

              Comment

              • pvong

                #8
                Re: Simple Pulbic Variable

                Thanks you both. I will use a Session and clear it on page load not
                postback.

                Phil

                "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@mi crosoft.com...
                pvong,
                >
                A webpage is not persisitent, in other words, all information in the class
                will be destroyed at the moment that you send the page.
                >
                To make things global for a page of a certain user there are 3 methods,
                for which in my idea the session.item is in most cases the most effective
                to use.
                >
                Cor

                Comment

                Working...