Simple Pulbic Variable

  • Thread starter Thread starter pvong
  • Start date Start date
P

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!
 
If you want to use it within the page, declare it within the class
definition
like

Private GroupID as Integer

Regards,

Trevor Benedict
MCSD
 
Perfect! Thanks!

Trevor Benedict said:
If you want to use it within the page, declare it within the class
definition
like

Private GroupID as Integer

Regards,

Trevor Benedict
MCSD
 
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
 
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
 
Cor Ligthert said:
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
 
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
 
Back
Top