Re: Global variable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David Jessee (djessee_at_houston.rr.com)
Date: 04/29/04


Date: Thu, 29 Apr 2004 00:24:55 -0500

There's a way around this, thought its not direct, depending on the context
of your "Global" definition.

You can access Cookie values through JavaScript. If you manage a variable
by always referring to a value inside of the client's cookie, then that
should work. (Global within a User's context, as opposed to a session
context)

You could, instead of using a js variable (var x;) always refer to a value
that is inside of a hidden field (make sure that the hidden field is set to
runat="server"). This would be "global" within a given page context.

You could subclass your page class. Create a Class, deriving from page,
that has a hidden field. When the page posts back, you perform some sort of
synch operation with that hidden field and an application/Session variable
and expose that value as a property of the page. That way all of the pages
that derive from this subclass would automatically have access to that
variable (effectively creates a "Global" Session/Applicatoin) level value
that script can access). Side Note...if you subclass your Page class,
you'll want to place the subclass inside of a seperate assembly and set a
reference to it in the Visual Studio IDE, otherwise the designer gets a
little funky.

If there's any way around doing this, I'd recommend it. Take a step back
and see if there's something you can do to your architecture to make this
unnecessary. However, these approaches should work if you have to take the
approach you're looking at.

"ruca" <ruuca@iol.pt> wrote in message
news:%23e05hDQLEHA.1192@TK2MSFTNGP11.phx.gbl...
> How can I declare a global variable in my .js file, that I can preserve
her
> value each time I need to call any function of .JS file in my ASP.NET
> application?
>
> Example:
> var aux=null;
>
> function myFunction1()
> {
> ...
> }
>
> function myFunction2()
> {
> ...
> }
>
> Now when I call myFunction1(), aux = true, and when I call myFunction2(),
> aux = false. The problem is that I need to preserve the previous value to

> test it in both functions. How?
> Help me please.
>
> Both functions are called in click event of 2 button's.
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
>



Relevant Pages

  • Re: Design help...an explosion of interfaces......
    ... >>comment on any subclass access problem. ... > Its pretty clear that some transactions between client code and Pipe ... one has logical encapsulation of the context ...
    (comp.object)
  • Re: Design help...an explosion of interfaces......
    ... > pipe implementations have the same interface signatures their ... I agree with Daniel T. et al that the context needs to be explained ... comment on any subclass access problem. ... If your client cares whether the pipe is buffered or not, ...
    (comp.object)
  • Re: Division by zero: float vs. int
    ... You can, of course, subclass Double, and provide your own definition ... And, of course, sqrtis not the only function which returns NaN. ... Are you perhaps thinking that the range for floating point ... In what context do you want to be able to say ...
    (comp.lang.java.programmer)
  • Re: lock Richtextbox to a given font
    ... > You can most likely subclass the box, test for WM_PASTE, swallow that, ... set AutoVerbMenu = False and build your own context menu. ... Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer) ...
    (microsoft.public.vb.general.discussion)