Home All Groups Group Topic Archive Search About

Simple Pulbic Variable

Author
27 Nov 2007 10:57 PM
pvong
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!

Author
27 Nov 2007 11:33 PM
Trevor Benedict
If you want to use it within the page, declare it within the class
definition
like

Private GroupID as Integer

Regards,

Trevor Benedict
MCSD

Show quoteHide quote
"pvong" <phillip*at*yahoo*dot*com> wrote in message
news:%23%23S16hUMIHA.1188@TK2MSFTNGP04.phx.gbl...
> 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!
>
Author
28 Nov 2007 12:05 AM
pvong
Perfect!  Thanks!

Show quoteHide quote
"Trevor Benedict" <TrevorN***@yahoo.com> wrote in message
news:OWtxi5UMIHA.2208@TK2MSFTNGP06.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*yahoo*dot*com> wrote in message
> news:%23%23S16hUMIHA.1188@TK2MSFTNGP04.phx.gbl...
>> 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!
>>
>
>
Author
28 Nov 2007 3:47 AM
pvong
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.SqlClient

Partial Class Client_ClientMtgNote

Inherits System.Web.UI.Page

Public groupid As Integer

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




Show quoteHide quote
"Trevor Benedict" <TrevorN***@yahoo.com> wrote in message
news:OWtxi5UMIHA.2208@TK2MSFTNGP06.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*yahoo*dot*com> wrote in message
> news:%23%23S16hUMIHA.1188@TK2MSFTNGP04.phx.gbl...
>> 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!
>>
>
>
Author
28 Nov 2007 5:34 AM
Cor Ligthert[MVP]
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
Author
28 Nov 2007 5:07 PM
Mythran
"Cor Ligthert[MVP]" <notmyfirstn***@planet.nl> wrote in message
news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@microsoft.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("MyPropertyName") = MyValue

HTH,
Mythran
Author
28 Nov 2007 5:55 PM
Cor Ligthert[MVP]
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

Show quoteHide quote
"Mythran" <kip_pot***@hotmail.com> schreef in bericht
news:7DA0D4ED-86EF-4EB8-A2F3-8B741416B603@microsoft.com...
>
>
> "Cor Ligthert[MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@microsoft.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("MyPropertyName") = MyValue
>
> HTH,
> Mythran
>
>
Author
28 Nov 2007 7:48 PM
pvong
Thanks you both.  I will use a Session and clear it on page load not
postback.

Phil

Show quoteHide quote
"Cor Ligthert[MVP]" <notmyfirstn***@planet.nl> wrote in message
news:A6239591-41E0-43C9-A796-CD4F7C3F1C14@microsoft.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