Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Name is not declared

Reply
Thread Tools

Name is not declared

 
 
DC Gringo
Guest
Posts: n/a
 
      02-27-2004
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


 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      02-27-2004
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" <(E-Mail Removed)> wrote in message
news:eU6whuT$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
declared or not declared ? JohnZing ASP .Net 3 02-05-2006 08:38 PM
Name 'SqlDbType' is not declared? Jerome ASP .Net 9 04-27-2004 03:00 PM
Name <whatever> not declared?!?!?! Aaargh!! Scott M. ASP .Net 2 02-05-2004 06:18 PM
"name not declared" but it is TJS ASP .Net 2 02-03-2004 11:47 PM
Name 'DiffGram' is not declared. Guoqi Zheng ASP .Net 0 01-12-2004 04:42 PM



Advertisments