reference to a "global" variable from within an aspx page

Discussion in 'ASP .Net' started by Pierre, Jan 13, 2006.

  1. Pierre

    Pierre Guest

    Hello,

    In an aspx page (mypage.aspx) from a web projet,
    I would like to get the value of a variable of the projet that is declared
    as public in a module.
    The variable can be called from anywhere in the code behind page and in the
    class files, but when I try to call it from an aspx page, it raises an
    error.

    <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not declared.

    I have a workaround, but it does not satisfy me enough :

    I create a code behind for the aspx page and I declared a class variable,
    let's say "cls_myvar", with a default value equals to "myvar".
    And now when referencing the "cls_myvar" in the aspx page, there is no error
    and the value is here.

    <%=cls_myvar%> is ok.

    But I would like to reference to the global var "myvar" in the simpliest
    way, ie whithout having to create a code behind file.

    Thanks for any help.

    Pierre.
    Pierre, Jan 13, 2006
    #1
    1. Advertising

  2. Pierre

    Dan Guest

    Hi Pierre,

    Personally one of the best features of .net is that we can now pull just
    about every bit of code out of the form page itself so that web designers
    and programmers can both work on what they do best. I have made so many
    large sites and never needed to write <% =myVar %> , not since asp anyway.

    Whatever it is you are setting to that value surely can be done on the code
    behind with no need to go into the html?

    Anyway i think your missing an understanding of classes. You said that you
    set the var to public in the class, this makes that var public to everything
    in that class and anything else from outside that makes an instance of that
    object, in other words you haven't made a application global var, you have
    made a class global var.

    What you want to be doing is make an application global var in your
    global.asx (thats what it is there for). Once you do this every aspx page
    will be able to reference the global var.

    I would then reference that global var in my code behind files to set values
    in the page. I get the impression you prefer not to use the code behind
    file? Why?

    Anyway i hope that helps

    --
    Dan
    "Pierre" <> wrote in message
    news:%...
    > Hello,
    >
    > In an aspx page (mypage.aspx) from a web projet,
    > I would like to get the value of a variable of the projet that is declared
    > as public in a module.
    > The variable can be called from anywhere in the code behind page and in
    > the class files, but when I try to call it from an aspx page, it raises an
    > error.
    >
    > <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
    > declared.
    >
    > I have a workaround, but it does not satisfy me enough :
    >
    > I create a code behind for the aspx page and I declared a class variable,
    > let's say "cls_myvar", with a default value equals to "myvar".
    > And now when referencing the "cls_myvar" in the aspx page, there is no
    > error and the value is here.
    >
    > <%=cls_myvar%> is ok.
    >
    > But I would like to reference to the global var "myvar" in the simpliest
    > way, ie whithout having to create a code behind file.
    >
    > Thanks for any help.
    >
    > Pierre.
    >
    >
    Dan, Jan 13, 2006
    #2
    1. Advertising

  3. Global's values can be seen by every user, so that is a no no.

    "Pierre" <> schreef in bericht
    news:%...
    > Hello,
    >
    > In an aspx page (mypage.aspx) from a web projet,
    > I would like to get the value of a variable of the projet that is declared
    > as public in a module.
    > The variable can be called from anywhere in the code behind page and in
    > the class files, but when I try to call it from an aspx page, it raises an
    > error.
    >
    > <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
    > declared.
    >
    > I have a workaround, but it does not satisfy me enough :
    >
    > I create a code behind for the aspx page and I declared a class variable,
    > let's say "cls_myvar", with a default value equals to "myvar".
    > And now when referencing the "cls_myvar" in the aspx page, there is no
    > error and the value is here.
    >
    > <%=cls_myvar%> is ok.
    >
    > But I would like to reference to the global var "myvar" in the simpliest
    > way, ie whithout having to create a code behind file.
    >
    > Thanks for any help.
    >
    > Pierre.
    >
    >
    Edwin Knoppert, Jan 13, 2006
    #3
  4. Pierre

    Pierre Guest

    Hello hello

    Thank you for taking care af my OOP knowledge.
    The pratical case is :
    a plateform used localy for developpement (http://localhost/project), and
    accedeed remotly by the custumer (http://www.dummy.com/project). Javascript
    is used in the pages, with CSS and Images.
    As you know (because you may know a lot of things, included the OOP), there
    is some issues regarding the path to access to the CSS and images from the
    javascript. In other word, there is a need for absolute url. The global var,
    then, is dedicated to set the path dynamically in the url string inside the
    CSS and the javascript file according to the access type : localy or
    remotely.
    As I do not want to build a gas factory to solve this issue that is raised
    only during the dev, I just need a simple global var for that, temporary.
    So everthing else is superfetatoire my dear.

    See you.

    Pierre.



    "Pierre" <> a écrit dans le message de news:
    %...
    > Hello,
    >
    > In an aspx page (mypage.aspx) from a web projet,
    > I would like to get the value of a variable of the projet that is declared
    > as public in a module.
    > The variable can be called from anywhere in the code behind page and in
    > the class files, but when I try to call it from an aspx page, it raises an
    > error.
    >
    > <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
    > declared.
    >
    > I have a workaround, but it does not satisfy me enough :
    >
    > I create a code behind for the aspx page and I declared a class variable,
    > let's say "cls_myvar", with a default value equals to "myvar".
    > And now when referencing the "cls_myvar" in the aspx page, there is no
    > error and the value is here.
    >
    > <%=cls_myvar%> is ok.
    >
    > But I would like to reference to the global var "myvar" in the simpliest
    > way, ie whithout having to create a code behind file.
    >
    > Thanks for any help.
    >
    > Pierre.
    >
    >
    Pierre, Jan 13, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alain Sienaert

    Reference Delphi aspx page in VB.aspx

    Alain Sienaert, Jul 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    508
    Eliyahu Goldin
    Jul 22, 2004
  2. S_K
    Replies:
    1
    Views:
    380
    IfThenElse
    Oct 2, 2007
  3. S_K
    Replies:
    0
    Views:
    368
  4. S_K
    Replies:
    0
    Views:
    406
  5. S_K
    Replies:
    0
    Views:
    352
Loading...

Share This Page