Name is not declared

Discussion in 'ASP .Net' started by DC Gringo, Feb 27, 2004.

  1. DC Gringo

    DC Gringo Guest

    I'm getting a BC30451: Name 'pageID' is not declared.

    I have a user control that contains a simple condition to display one row or
    another like:

    <% If x = 1 Then %>
    ....some html...
    <% Else %>
    ....some html...
    <% End If %>

    The control is used to in two different .aspx pages (e.g. first.aspx and
    second.aspx). In each .aspx page, I've tried to set this variable right
    after Private Sub Page_Load in the code-behind page to no avail...such as:

    Public Class WebForm1
    Inherits System.Web.UI.Page
    Web Form Designer Generated Code

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Dim x As Integer = 10000

    End Class

    --
    _____
    DC G
     
    DC Gringo, Feb 27, 2004
    #1
    1. Advertising

  2. Hi, DC Gringo

    Although your design is wrong, the solution is the following:

    Create a property x of type Integer in the class of the usercontrol. Also a
    public field of the class will work, but it is one of the worst things you
    can do in the OOP world.
    Assign this property (or field) from the Page in the Page_Load method.

    Now, the good design:

    Put the part between <% If x = 1 Then %> and <% Else %> in one
    Panel/PlaceHolder/whatever container control with runat="server" and the
    part between <% Else %> and <% End If %> in another container control with
    runat="server" and visible="false". Remove <% If x = 1 Then %>, <% Else %>
    and <% End If %>
    In the class of the usercontrol add a method to switch the visibilities,
    i.e.:

    Public Sub SwitchVisibility(ByVal showFirstPanel As Boolean)
    panel1.Visible = showFirstPanel
    panel2.Visible = Not(showFirstPanel)
    End Sub

    Call this method on the instance of the usercontrol from the Page_Load of
    the Page with the parameter you need.

    Greetings
    Martin
    "DC Gringo" <> wrote in message
    news:eU6whuT$...
    > I'm getting a BC30451: Name 'pageID' is not declared.
    >
    > I have a user control that contains a simple condition to display one row

    or
    > another like:
    >
    > <% If x = 1 Then %>
    > ...some html...
    > <% Else %>
    > ...some html...
    > <% End If %>
    >
    > The control is used to in two different .aspx pages (e.g. first.aspx and
    > second.aspx). In each .aspx page, I've tried to set this variable right
    > after Private Sub Page_Load in the code-behind page to no avail...such as:
    >
    > Public Class WebForm1
    > Inherits System.Web.UI.Page
    > Web Form Designer Generated Code
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > End Sub
    >
    > Dim x As Integer = 10000
    >
    > End Class
    >
    > --
    > _____
    > DC G
    >
    >
     
    Martin Dechev, Feb 27, 2004
    #2
    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:
    380
    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,897
    vMike
    Feb 3, 2004
  3. Scott M.
    Replies:
    2
    Views:
    533
    Kevin Spencer
    Feb 5, 2004
  4. Jerome

    Name 'SqlDbType' is not declared?

    Jerome, Apr 27, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    1,577
    Jerome
    Apr 27, 2004
  5. JohnZing

    declared or not declared ?

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

Share This Page