name 'a' is not declared

Discussion in 'ASP .Net' started by Ben, Aug 23, 2009.

  1. Ben

    Ben Guest

    Hi,

    in code-behind, i have:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load
    Dim a As Integer
    a = 5
    End Sub

    i want to use that variable in the aspx file:

    <body>
    <form id="form1" runat="server">
    <%=a%>
    </form>
    </body>

    but i get the error: name 'a' is not declared.

    Where and how do i have to declare 'a'?

    Thanks
    Ben
     
    Ben, Aug 23, 2009
    #1
    1. Advertising

  2. Ben

    Ben Guest

    both, but i found it by myself: instead of DIM, just FRIEND as declaration.

    "Mark Rae [MVP]" <> schreef in bericht
    news:...
    > "Ben" <> wrote in message
    > news:...
    >
    >> I want to use that variable in the aspx file:
    >>
    >> <body>
    >> <form id="form1" runat="server">
    >> <%=a%>
    >> </form>
    >> </body>
    >>
    >> but I get the error: name 'a' is not declared.

    >
    > Yes, you would do...
    >
    >
    >> Where and how do I have to declare 'a'?

    >
    > You'll need to define what you mean by "use that variable in the aspx
    > file"... Do you mean that you want to populate a DOM element's value with
    > the server-side variable? Or do you mean that you want to use the
    > server-side variable in e.g. a client-side script...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Ben, Aug 24, 2009
    #2
    1. Advertising

  3. Ben wrote:
    > Hi,
    >
    > in code-behind, i have:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    > Handles Me.Load
    > Dim a As Integer
    > a = 5
    > End Sub
    >
    > i want to use that variable in the aspx file:
    >
    > <body>
    > <form id="form1" runat="server">
    > <%=a%>
    > </form>
    > </body>
    >
    > but i get the error: name 'a' is not declared.
    >
    > Where and how do i have to declare 'a'?
    >
    > Thanks
    > Ben
    >


    You are declaring the variable as local in the method. To access if from
    the aspx code you have to declare it as a protected (or public) member
    of the class intead.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    Göran Andersson, Aug 25, 2009
    #3
    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. Guoqi Zheng

    Name 'DiffGram' is not declared.

    Guoqi Zheng, Jan 12, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    374
    Guoqi Zheng
    Jan 12, 2004
  2. TJS

    "name not declared" but it is

    TJS, Feb 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,868
    vMike
    Feb 3, 2004
  3. Scott M.
    Replies:
    2
    Views:
    528
    Kevin Spencer
    Feb 5, 2004
  4. DC Gringo

    Name is not declared

    DC Gringo, Feb 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,851
    Martin Dechev
    Feb 27, 2004
  5. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,595
    Jon Paal
    Feb 5, 2006
Loading...

Share This Page